Torque Script Array documentions
by Thomas Olsen · in Technical Issues · 10/04/2006 (9:09 am) · 4 replies
I am new to Torque and am trying to find some documentation on array commands in Torque Script. For example, in C++ you can declare the size of an array and access array properties like length, etc.
So far, I havent found any documentation for those commands. Hopefully someoen can point me in the right direction.
Thanks!
So far, I havent found any documentation for those commands. Hopefully someoen can point me in the right direction.
Thanks!
#2
I end up doing things like this:
$arrayLen = 0;
$array[$arrayLen] = "first item"; $arrayLen++;
$array[$arrayLen] = "next item"; $arrayLen++;
$array[$arrayLen] = "next item"; $arrayLen++;
and so on.
You should also look into SimSets and SimGroups which are convenient ways of storing objects but not so good for storing raw data like strings. SimSets and SimGroups do have the usual length() and other methods.
10/04/2006 (10:23 am)
This means there is no $array.length() method.I end up doing things like this:
$arrayLen = 0;
$array[$arrayLen] = "first item"; $arrayLen++;
$array[$arrayLen] = "next item"; $arrayLen++;
$array[$arrayLen] = "next item"; $arrayLen++;
and so on.
You should also look into SimSets and SimGroups which are convenient ways of storing objects but not so good for storing raw data like strings. SimSets and SimGroups do have the usual length() and other methods.
#3
10/04/2006 (1:04 pm)
Thanks for the clarification!
#4
10/04/2006 (1:22 pm)
The fake "array" notation in TS is actually kind of cool. Though Manoel touched on it, being able to make dynamicly built variable names or references is pretty fun. So like saying you had:$fakeArray[L0] $fakeArray[L1] $fakeArray[L2] $fakeArray[L3] $fakeArray[R0] $fakeArray[R1] $fakeArray[R2] $fakeArray[R3]You could reference them in code with something like
for(%i = 0; %i < 4; %i++) $fakeArray[%dir @ %i] = stuff;I remember using a system where I had to create a local dynamic variable on a player that was unique for each weapon, so I set the variable with the [%weaponID] tagged onto it to keep them all unique.
Associate Manoel Neto
Default Studio Name
What the array-esque syntax does is allowing you to build variable names using dynamic data, without resorting to eval().
Example:
$array[4] ------> $array4