| Arrays |
|---|
Arrays are arranged lists of values. <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. 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. 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. 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. |