Arrays¶
Arrays allow you to store multiple values in a single variable. They are useful for storing lists of things, e.g. a list of units you want the AI to train.
1. Creating an array¶
To create an array, you need to use one of the following functions (depending on the data type you want to store):
Signatures of xsArrayCreate
functions
1.1. Array size¶
The size
parameter specifies how many elements the array should have. It is
not possible to add more elements to an array than its size. If you want to
add more elements to an array, you need to use the xsArrayResize
functions.
1.2. Array name¶
This is used for debugging purposes, and must be unique. It can be a concise name or a slightly longer description of what the array is used for.
1.3. Array default value¶
This is the value that will be assigned to each element of the array when it is created. Until you assign a different value to an element, it will have this value.
2. Accessing array elements¶
To access an element of an array, you need to use one of the following functions (depending on the data type the array stores):
Signatures of xsArrayGet
functions
2.1. Array ID¶
This is the ID of the array you want to access. It is returned by the
xsArrayCreate
functions.
2.2. Array index¶
This is the index of the element you want to access. The first element of an array has index 0, the second element has index 1, and so on. If the index is out of bounds (i.e. less than 0 or greater than or equal to the array size), the function will return the default value of the array.
3. Assigning values to array elements¶
To assign a value to an element of an array, you need to use one of the following functions (depending on the data type the array stores):
Signatures of xsArraySet
functions
3.1. Array ID¶
This is the ID of the array you want to access. It is returned by the
xsArrayCreate
functions.
3.2. Array index¶
This is the index of the element you want to access. The first element of an array has index 0, the second element has index 1, and so on. If the index is out of bounds (i.e. less than 0 or greater than or equal to the array size), the function will do nothing.
3.3. Value¶
This is the value you want to assign to the element. It must be of the same data type as the array.
4. Resizing arrays¶
To resize an array, you need to use one of the following functions (depending on the data type the array stores):
Signatures of xsArrayResize
functions
4.1. Array ID¶
This is the ID of the array you want to resize. It is returned by the
xsArrayCreate
functions.
4.2. New size¶
This is the new size of the array. If it's less than the current size, the array will be truncated. If it's greater than the current size, the array will be extended, and the new elements will be initialized to the default value of the array. If it's negative, the function will do nothing and the array will remain unchanged.
5. Examples¶
Example of array usage