UE1 - UT Array in function call

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

playsax

New Member
Feb 20, 2008
44
0
0
From the documentation:
You can pass any UnrealScript types to a function (including arrays)

So intuitively I tried the following, which is not compiling:
Code:
function Hi()
{
local byte test[2];

Hello(test); // Pass array
}

function Hello(byte test)
{
}

Please enlighten me on how to pass an array to a function?
 
Last edited:

FXD|Shadow

Mad Man, really
It's not working, because you're passing the array without any indexing: SomeArray[INDEX], the indexing is the position of an element inside an array, like SomeArray[0] = FirstElement, SomeArray[1] = SecondElement and so on. In arrays we start counting with 0. Please remember that in UE1 you can only pass staticarrays that way.
 
Last edited:

brold9999

New Member
Apr 5, 2009
142
0
0
I think he wants to pass the entire array, not a single element from it. It's been a while since I've coded in UT99 but I believe the syntax is either

Code:
function Hello(byte test[2])

or

Code:
function Hello(byte[] test)

Probably the first one.
 

FXD|Shadow

Mad Man, really
Your first example passes the imaginary third element of the array "Test", but Test has only 2 elements ([0] and [1]), so this may lead to the "accessed array out of bounds" error.

The second example passes nothing and leads to an error too ("bad or missing expression in array index", because no index has been set at all). We also index the variable name, not the variable type. byte[INDEX] variable -> wrong, byte variable[INDEX] -> right

To pass the entire array to a function one needs to loop through that array, using a for loop for example.

Code:
function Hi()
{
local byte test[2];
local int i;

for (i=0; i<2; i++)
  Hello(test[i]); 
}

function Hello(byte test)
{
}

Additionally we can control whether an element has been set (some number 1 to 255 for the byte example) or not (= 0)

Code:
function Hi()
{
local byte test[2];
local int i;

for (i=0; i<2; i++)
{
  if (test[i] != 0)
    Hello(test[i]); 
}
}

So he loops only through the elements that are actually set.
 
Last edited:

brold9999

New Member
Apr 5, 2009
142
0
0
Your first example passes the imaginary third element of the array "Test", but Test has only 2 elements ([0] and [1]), so this may lead to the "accessed array out of bounds" error.

The second example passes nothing and leads to an error too ("bad or missing expression in array index", because no index has been set at all).

My example doesn't pass anything because it's not a function call, it is a function declaration with an array parameter of size 2.
 

brold9999

New Member
Apr 5, 2009
142
0
0
I haven't tested it on UE1, but I just tested it on UT2004 and it works there.

Complete code: (using UnrealUtilityLib for the test framework)

Code:
class ArraySyntaxTests extends AutomatedTest;

simulated function runTests() {
  myAssert(testA() == 5, "test passing an array");
}

function byte testA() {
  local byte tvar[2];
  
  tvar[0] = 3;
  tvar[1] = 2;
  
  return testB(tvar);
}

function byte testB(byte param[2]) {
  return param[0] + param[1];
}
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
I'm quite sure array passing works in UE1 as well. Just make sure the array's memory size is below 256 bytes (e.g. byte arrays up to 255 elements, int arrays up to 63 elements, etc.) and that the array you want to pass has the same size as the function parameter expects. Note that replicated function calls will not pass arrays correctly as they only ever replicate the first array element, unless you put the array into a struct.
 

playsax

New Member
Feb 20, 2008
44
0
0
Passing an entire array in UT1 doesn't seem possible, so I'll just stick to passing the individual elements which I was already doing (e.g. Hello(test[0], test[1])). It works fine, just a bit cumbersome.
 
Last edited:

AnthraX

New Member
Aug 3, 2005
20
0
0
39
Ghent (Belgium)
I'm quite sure array passing works in UE1 as well. Just make sure the array's memory size is below 256 bytes (e.g. byte arrays up to 255 elements, int arrays up to 63 elements, etc.) and that the array you want to pass has the same size as the function parameter expects. Note that replicated function calls will not pass arrays correctly as they only ever replicate the first array element, unless you put the array into a struct.

Confirmed. Passing arrays works fine in UE1. Example:

Code:
simulated function GenerateArray()
{
    local int Test[16];
    local int i;

    for (i = 0; i < 16; ++i)
        Test[i] = i;
    
    LogArray(Test);
}

simulated function LogArray(int Arr[16])
{
    local int i;

    for (i = 0; i < 16; ++i)
        Log("Arr[" $ i $ "]= " $ i);
}