Arrays
An array represents an indexed collection of elements of the same type (called the base type). You can work with any element directly via its index. An index numeration begins with a zero. Arrays are supported in San Andreas, LCS and VCS.
General Syntax
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.
Array Declaration
Arrays can be declared using the var
keyword (similar to variables):
You can declare arrays of primitive types (such as numbers or strings) using a more concise syntax:
The type can be one of the following: Int
, Float
, String
, or LongString
:
Accessing array elements after declaration
After declaring an array, you can access its elements using square brackets:
Elements of an array containing string literals can be accessed using string variables:
An array can be declared as a collection of class instances, its methods are available for each element:
By default, the disassembler prints array elements with the numbers as indexes in the GTA SA
edit mode. The same feature is available in LCS and VCS but is disabled by default. You can turn this feature on and off using the debug option CONSTANT_INDEXES
.
Last updated