Vice City Multiplayer

VC:MP 0.4 (Beta) => Script Discussion => Topic started by: sseebbyy on September 16, 2014, 06:25:30 pm

Title: How to make a "double array" ?
Post by: sseebbyy on September 16, 2014, 06:25:30 pm
I'm working on a project, and I need double array to can decrease the number of lines used for it.
(I need it to run the globan function)

What I call a "double array" ? This:
Code: [Select]
myarray[0][0];
myarray[1][0];

myarray[0][0] is not the same with myarray[1][0];.
Is it possible ?
Title: Re: How to make a "double array" ?
Post by: S.L.C on September 16, 2014, 06:49:15 pm
You mean like a multidimensional array? Like in the following example:

Code: [Select]
arr <- [
["sub array 0", true, 54, 0.45],
["sub array 2", false, 213.6, 32],
["sub array 3", false, 9897, 45.425],
["sub array 4", true, 321.2353, 32]
];

foreach (sub in arr)
{
print(format("\n%s elements are the following:\n", sub[0]));

print(format("\telement 1 is of type %s with the value %s\n", typeof sub[1], sub[1].tostring()));

print(format("\telement 2 is of type %s with the value %s\n", typeof sub[2], sub[2].tostring()));

print(format("\telement 3 is of type %s with the value %s\n", typeof sub[3], sub[3].tostring()));
}

Output should be:
Code: [Select]
sub array 0 elements are the following:
        element 1 is of type bool with the value true
        element 2 is of type integer with the value 54
        element 3 is of type float with the value 0.45

sub array 2 elements are the following:
        element 1 is of type bool with the value false
        element 2 is of type float with the value 213.6
        element 3 is of type integer with the value 32

sub array 3 elements are the following:
        element 1 is of type bool with the value false
        element 2 is of type integer with the value 9897
        element 3 is of type float with the value 45.425

sub array 4 elements are the following:
        element 1 is of type bool with the value true
        element 2 is of type float with the value 321.235
        element 3 is of type integer with the value 32
Title: Re: How to make a "double array" ?
Post by: sseebbyy on September 17, 2014, 12:01:12 am
Thank you for reply, but it is not what I need.

Knucis and Gudio were right, and I was noob.
The code is this:
(I use it in a class, so is the example)

Code: [Select]
t = array(sizeofarray,null);
for(local i = 0; i < t.len(); i++)
{
        t[i] = array(sizeofsecondarray,null);
}

I used "local i = 1" instead of "local i = 0" because I was thinking about something related to my project. (that you may find out after I public the script)
I knew that arrays starts with 0, but like I said, I was thinking about something else used few lines under.

Thank you very much, Gudio and Knucis ! :/

Topic locked.