arrays

Started by KAKAN, Oct 09, 2015, 01:16 PM

Previous topic - Next topic

KAKAN

I made 2 arrays
One at top of the script as:-
Array1 <- [1,2,3];

2nd one at onScriptLoad as:-
Array2 <- array(1,2,3)

Now I executed them as:-
foreach(a in Array1)
{
print(a);
}
Output:-
3
2
1

2nd one as:-
foreach(a in Array2)
{
print(a);
}
Output:-
2
So what's the difference between a array and a global variable?
oh no

.

#1
You dumb f... How many times have I told you to read the documentation. array(...) is just a helper function that takes a number and a value and then creates an array with the size of the specified number and fills it with the specified value. Equivalent of:

function array(size, fill = null)
{
    local a = [];
    a.resize(size, fill);
    return a;
}

Therefore your second statement creates and array with 1 element and fills all elements (meaning a single element) with the integer value `2`. The third argument is discarded/ignored.

.

KAKAN

Thanks again!
Solved
oh no