Mod:Creation Kit/Array Reference

Arrays are values that contain several other values, indexed by a 0-based number. (0 is the first element, 1 in the second, and so on).

Array Type


An array type is denoted by adding a pair of empty brackets after the type of the elements. The element type may only be a non-array type, so multi-dimentional arrays are not allowed. These types can be used anywhere else other types are used - as parameter, return, variable, and property types.

Examples
int[] MyObject[]
 * An array of integers
 * An array of MyObjects

Array Creation


To create an array, use the "new" keyword, followed by the type and size. The Size is denoted by the integer between the two square brackets, but that number may come from an expression or variable.

The initial value of each element will be the default value for the type.

If you make an array property, then the Creation Kit will determine the size of the array by how many elements are put into it.

Note that this cannot appear in the script outside of a function.

Examples
float[] x = new float[20] MyScript[] x = new MyScript[5 * count]
 * Create an array of 20 floats
 * Create an array of 5*count MyScripts

Array Length


To get the length of an array, you can access the read-only length property on the variable holding the array. If the variable is None, the length will still succeed, but return 0. Note that the last valid index in an array is the length of the array, minus 1.

Examples
int[] myArray = new int[10] x = myArray.Length ; x will get 10 float[] myArray x = myArray.Length ; x will get 0
 * Get the length of our array
 * Get the length of an uninitialized array (None)

Array Elements


To get a specific array element, just put the index of the element you want between two square brackets. This value can also come from an expression, or a return value of a function, or something else. The valid elements in an array are from 0 to the length minus 1.

Examples
x = myArray[0] x = myArray[myArray.Length - 1]
 * get the first element in the array
 * get the last element of the array

Array Functions
Several additional functions are available for arrays, listed below:
 * Mod:Creation Kit/Add - Array
 * Mod:Creation Kit/Clear - Array
 * Mod:Creation Kit/Find - Array
 * Mod:Creation Kit/FindStruct - Array
 * Mod:Creation Kit/Insert - Array
 * Mod:Creation Kit/Remove - Array
 * Mod:Creation Kit/RemoveLast - Array
 * Mod:Creation Kit/RFind - Array
 * Mod:Creation Kit/RFindStruct - Array