Author Topic: Why doesn't Blockland have foreach?  (Read 2478 times)

They aren't actual arrays though.
How an actual array would work:
$Variable = [0,5,3];
This would create $Variable as a pointer to an array, and set $Variable.length to 3, $Variable[0] to 0, etc.
$Variable[1] = 6; would then change it to [0,6,3]. Without the array existing, it would create $Variable as a pointer to the array, and set the value(s) accordingly.
This doesn't happen in TS.
When you do $Variable[1] = 6; $Variable is still null. There is no determinable length to it. All you're doing is actually setting $Variable1 = 6;
Example:
%x = 1;
%y = 2;
$Variable[%x,%y] = 1;
This is just doing
$Variable1_2 = 1;

There is no way to tell the engine how many things are in the 'array' when you use a foreach, in TorqueScript.

Just have
foreach(%a in $asdf[])

work like
for(%a = $asdf[%i = 0]; %a !$= ""; %a = $asdf[%i++])

and it will be just fine for most cases.
« Last Edit: May 24, 2016, 02:29:20 PM by Zeblote »

Basically what Zeblote said. It obviously doesn't exist, so if it were to exist it would just have to be made in a way that copes with pointers. Create the function to work with $Variable[] instead of $Variable.

We really don't need more syntactical sugar. We got plenty.

We really don't need more syntactical sugar. We got plenty.
I do, bug off.
ily <3