Author Topic: [] Brackets.  (Read 1796 times)

Yeah, i continuosly see them brackets as im looking through scripts What they for.

[] Them ones.

They are for arrays; lists of data.

Example:
Code: [Select]
$var[0] = "Hello";
$var[1] = " ";
$var[2] = "world";
$var[3] = "!";
for(%i=0;%i<4;%i++){
   %str = %str @ $var[%i];
}
echo(%str);
It loops throuch each element in the array and adds it to the end of the string.

And it puts the lowest number first and goes thorough? so
  • then [1] then [2] etc...

Thank you guys, i think i get it now.

Torque's method of "Arrays" is like this:

$inv[0] is the same as "$inv0".
$inv["Hello"] is the same as "$invHello".
$inv["entory"]item is the same as "$inventoryitem".
$inv[3,4] is the same as "$inv3_4" or $inv["3_4"].

Scripts like in above posts can help when looping through large amounts of different variables to find a specific one, i.e. large inventory lists. Instead of %invFirstSlot you'd have %inv[0] or [1].

So arrays dont have to be numbers.

http://www.cprogramming.com/tutorial/c/lesson8.html

Yeah, i know C != Torquescript, but arrays are pretty much the same in all languages that use them.