Author Topic: Arrays  (Read 1210 times)

I don't quite get what they do or how to use them, do they do this..

if %i = "1";
and %client.a = "2 3 4";
then you do %client.a[%i]
%client.a[%i] is like %client.a1?

An array is just something like this:

%cow.eats["grass"] = true;
%cow.eats["hay"] = false;
%cow.drinks["milk"] = false;

And you could then find out the values by doing:
%foodType = "grass";
if(%cow.eats[%foodType])
     echo("The Cow DOES eat Grass!");

You can basically add onto another variable that an object has, so you could also make:

%horse.food[1] = "Hay";
%horse.food[2] = "Saltlick";
%horse.food[3] = "Cranberry Juice";

And you could loop through all these by doing:
%i = 1;
%food = %horse.food[%i];
while(%food !$= "")
{
     echo("The horse eats "@ %food);
     %food = %horse.food[%i++];
}

Or something. I'm sure theres another thread on this somewhere.

Thanks Ephi, I've got it now.

How would you pass an entire array to a method?

How would you pass an entire array to a method?
You can't. The only way to fix it is wrap it in a simobject/simset.

You can't. The only way to fix it is wrap it in a simobject/simset.

Please explain.

Ephis' first example reminds me more of a map than an array.