Arrays
Arrays are used to store sequences of variables, or 'elements'. An element within an array is accessed by 'indexing' the array with an integer offset.
The general syntax for indexing an array is:
Array[Index1,Index2 etc...]
Creating Arrays
The most common way to create an array is when declaring a variable:
Local int_array[10]
This will initialize the int_array variable with a 10 element array. You can declare an 'empty' array by using []:
Local int_array[]
An empty array is identical to an array with 0 elements.
Arrays may also be created 'on the fly' using the syntax:
New ElementType[Dimension1,Dimension2 etc...]
This returns an array of the specified dimension(s) with each element initialized to Null. For example:
Local int_array:Int[]
int_array=New Int[10]
'Auto arrays' may be created using the syntax:
[Element1,Element2 etc...]
This returns a 1 dimensional array containing the specified elements, for example:
Local int_array[]=[1,2,3,4,5]
Each element of an auto array must have exactly the same type. If necessary, you can use type conversions to enforce this.
Arrays provide a Sort method and a read only length field. Sort takes an optional ascending parameter that defaults to true. Here is an example of sorting an array:
Strict
Local arr:String[]=["some","random","strings","in","a","string","array"]
arr.Sort 'sort ascending
Print "Array in ascending order..."
For Local t:String=EachIn arr
Print t
Next
arr.Sort False 'sort descending
Print "Array in descending order..."
For Local t:String=EachIn arr
Print t
Next
To copy an array, use a slice.