<RetVar> = The name you wish to give the array and the variable it will be stored in.
<Var/Number> = The size you wish the new array to be. This is the number of internal 'elements' to the array.
Creates and allocates an array with <Var/Number> elements and assigns the result to <RetVar>.
The size can be zero, which will give you an array with no elements (an empty array) – this array can be later appended to.
Arrays are always zero based (the first element is element zero).
Mulitiple arrays can be inside an array (an array of arrays).
These internal arrays can be created at the time the master array is created or they can be from a variety of sources, anywhere you get an array as a return for example.
Example array structures;
Example: 1,
This creates a single empty array
$master.array =array alloc: size = 0
Example: 2,
This creates an array with 4 internal arrays
First, create all the arrays,
Create main array
$master.array =array alloc: size = 4
Create sub arrays
$sub.array.1 =array alloc: size = 0
$sub.array.2 =array alloc: size = 0
$sub.array.3 =array alloc: size = 0
$sub.array.4 =array alloc: size = 0
Then place them where they need to be,
$master.array [ 0 ] = $sub.array.1
$master.array [ 1 ] = $sub.array.2
$master.array [ 2 ] = $sub.array.3
$master.array [ 3 ] = $sub.array.4
To retrieve the internal arrays, you would use,
$sub.array.1 = $master.array [ 0 ]
$sub.array.2 = $master.array [ 1 ]
$sub.array.2 = $master.array [ 2 ]
$sub.array.4 = $master.array [ 3 ]
The important thing about arrays is, that they are pointers to the actual data contained in them.
If two separate scripts grab $master.array from the same global variable, then both are simultaneously accessing the exact same physical array and not copies of it.
If one of these scripts does a $master.array = null then the other script will be completely unaffected.
All this script did was to sever it's link to the place where the array's data is stored.
To delete the data inside an array you have to use array functions like remove item or resize array.
Command Location:
- »» General Commands
- »» Arrays
<RetVar> = array alloc: size= <Var/Number>
- »» Arrays