Game Development Community

Multidimensional arrays

by Josef Jahn · in Torque Game Engine · 03/27/2003 (4:57 am) · 5 replies

Hi all,

Another strange twisted question: Do scripted multidimensional arrays really work?

I ask because %test[1][12] is being stored internally as %test112. You can do an export() and check for yourself. Of course there's the old %test[(%row * %rowsize) + %col] for the desperate. Still I wonder why it's not possible to separate dimensions with, say, an underscore. In short, %test[1][12] would become %test1_12 and vice versa.

Any thoughts?

#1
03/27/2003 (5:14 am)
Hi there,

In my experience, multidimensional arrays do work. However, they're used like this: %test[1, 12] and not %test[1][12] (c/c++ style). I'm not quite sure, how they're stored internally. Anyways I have no problems using them.

Stefan.
#2
03/27/2003 (5:17 am)
*slaps his forehead* - Comma separation! It would be interesting to see how those are stored. Well, I can try that out later today.

Thanks!
#3
03/27/2003 (5:32 am)
You're welcome. I'm glad that I'm not the only one that encountered that problem.
#4
11/09/2006 (4:04 pm)
Question: Is it truly a multidimensional array? or just a string? When i insert a two values for example: $aryMyArray[0,0] = "45 92";
echo ( $aryMyArray[0,0] );

This will print: "45 92", which is a string, now how do we access only the second value? Do we now have to parse the string with the NextToken function or whatever parsing function we choose? Am I missing something here on how to access that?

I've noticed that:
%aryMyArray[0,0] = "1 2 3 4 5 6 7 8 9";
echo (%aryMyArray[0,0] );

prints out: 1 2 3 4 5 6 7 8 9

So is it a true multidimensional array?
#5
11/09/2006 (4:35 pm)
Well,
you're setting the array element at 0,0 to the string "45 92".

it sounds like maybe you want something like
$array[0, 0] = 45;
$array[0, 1] = 92;