Creates an array of the required size
Device + Agent
Name | Type | Description |
---|---|---|
numberOfItems | Integer |
The number of items the new array will contain, ie. its size
|
fillValue | Any |
An optional fill value of any Squirrel data type
|
Array — a new array
This function creates a new array of the required size. If the optional second parameter is provided, each of the new array’s new items will be populated with a copy of the value — or a single reference to it if the value is another array, a blob, a function, an object or a table.
Squirrel supports only single-dimensional arrays, but it is possible to construct arrays of arrays to simulate multi-dimensional arrays. For example, a two-dimensional array might be created as follows:
const SCREEN_HORIZONTAL_PIXELS = 128;
const SCREEN_VERTICAL_PIXELS = 32;
local displayArray = array(SCREEN_VERTICAL_PIXELS);
for (local i = 0 ; i < SCREEN_VERTICAL_PIXELS ; i++) {
displayArray[i] = array(SCREEN_HORIZONTAL_PIXELS, 0xFF);
}
Accessing a element of this matrix would require the following code:
local oldPixelValue = displayArray[rowNumber][columnNumber];
displayArray[rowNumber][columnNumber] = newPixelValue;
If functions and/or objects are added to the array, the array can no longer be serialized (see Squirrel Data Serialization).