VC:MP 0.4 (Beta) > Script Discussion

How to make a "double array" ?

(1/1)

sseebbyy:
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: ---myarray[0][0];
myarray[1][0];
--- End code ---

myarray[0][0] is not the same with myarray[1][0];.
Is it possible ?

S.L.C:
You mean like a multidimensional array? Like in the following example:


--- Code: ---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()));
}

--- End code ---

Output should be:

--- Code: ---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

--- End code ---

sseebbyy:
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: ---t = array(sizeofarray,null);
for(local i = 0; i < t.len(); i++)
{
        t[i] = array(sizeofsecondarray,null);
}
--- End code ---

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.

Navigation

[0] Message Index

Go to full version