For the complete documentation index, see llms.txt. This page is also available as Markdown.

Arrays

An array represents an indexed collection of elements of the same type (called the base type).

Array Declaration

<type> <array name>[<size>]

The type can be one of the following: Int, Float, String, LongString or any available class name:

int intArray[10]
float floatArray[10]
string stringArray[10]
longstring longStringArray[10]
Car cars[5]

Accessing array elements after declaration

After declaring an array, you can access its elements using square brackets notation. Arrays use zero-based indexes, where the first element of the array is available at the index 0, the second one at the index 1, etc:

float values[10]
values[0] = 100.0

string stringArray[10]
stringArray[0] = 'str1'
stringArray[1] = 'str2'
stringArray[2] = 'str3'

longstring longStringArray[10]
longStringArray[0] = "str1"
longStringArray[1] = "str2"
longStringArray[2] = "str3"

You can also index array elements using variables, like so:

An element of an array can be used just like any other variable. If the array has a class type, each element can be used to call methods of that class:

Spreading Arrays

Arrays support spread syntax with the ... operator as a quick way to represent all array elements.

For example, if you have an array of 3 elements like so:

You can spread it to store the result of a command that returns three float numbers, e.g. get_char_coordinates:

You can also spread an array to pass all elements to a command that requires that amount of arguments, e.g. set_char_coordinates:

You can also use spread syntax when calling functions.

Legacy syntax

The legacy syntax is produced when you disassemble a script that uses arrays. This syntax represents low-level array implementation and is not recommended for direct use in new scripts. Instead, declare an array and access elements using square bracket notation (see above).

San Andreas

<array name>: a local or global variable <index var name>: any variable containing an index of the element to read or write <size>: a value between 1 and 255 (inclusive) <type>: one of characters i f s v:

Letter
Item Type
Item Size (bytes)

i

integer

4

f

float

4

s

string

8

v

string

16

Liberty City Stories, Vice City Stories

In LCS, VCS, array elements are only 4 bytes in length. Therefore, there is no need in type declaration.

Last updated