Arrays

 

Arrays are arranged lists of values.
A simple array declaration is structured like this:

		<access> <type> <identifier>[<length>];

Where <access> as previously stated can be one of public or private, <type> is a datatype (INT, BOOL, DROID, whatever), <identifier> is the name of the array, followed by the bracket and a numeric literal representing the length of the array, ended with another bracket and semicolon.

This creates a one dimensional array. Here's an example:

		private DROID myDroids[10];

This creates an array of 10 variables of type DROID. These variables are located at indexes ranging from 0 through 9.
This means that the highest accessible index value is always one less than the length of the array.
This is becase the index values are zero-based, so the first element in an array is always #0.

Here's how to fetch a value from an array:

		<target> = <arrayName>[<index>];

Where target is either a variable of the same type as the variables within the array, or a declaration of such a variable. <arrayName> is obviously the name of the array fromwhich the value contained at location <index> in the array should be fetched.
Index cannot be greater than 255, and therefor the maximum number of elements in an array dimension is 256.
(defined by LIB/Interp.h in the source line 116)

Assigning values to locations in an array is much the same as retrieving from it the array, only in reverse:

		<arrayName>[<index>] = <value>;

Where <value> can be any kind of expresion that evolves to a value compatible with that of the array.
Examples:

		myDroid = myDroids[0]; // get the first droid in the array

		private BASEOBJ myBObjs[5];
		myBObjs[0] = myDroid;
		myBObjs[1] = myDroids[2];

You can also create multidimensional arrays:

		<access> <type> <identifier>[x][y];

You do this by just adding extra bracket sections to the declaration. However, you can only have a maximum of 4 dimensions in an array.
(defined by LIB/Interp.h in the source line 115)