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

Const Arrays

Const arrays are basically compiler managed lists of data stored in the data section.

Syntax

// single dimensional
const <datatype> <n>[] = { <values> };

// two dimensional
const <datatype> <n>[][] = {
    { <values for the first "row"> },
    { <values for the second "row"> }
};

The difference between a single dimension array and a multi dimensional array is that the single dimension array is basically a single row with related data while a multi dimensional array allows for slightly better structured data of rows.

An example of when a multi dimensional array is preferred is when setting up values for different guns in a game. You can then have each row represent a single gun and the columns within have each value for it.

There is an important rule to keep in mind when working with multi dimensional arrays: each row must contain exactly the same number of values.

There is also an importance of choosing an appropriate data type, it will dictate what values you can use within the array. See the below table for more information about the available datatypes, their support, size, and range:

Datatype
Supports Multi-Dimension Arrays
Size Required Per Value
Minimum Value
Maximum Value

int8

Yes

8 bits (1 byte)

-128

127

uint8

Yes

8 bits (1 byte)

0

255

int16

Yes

16 bits (2 bytes)

-32,768

32,767

uint16

Yes

16 bits (2 bytes)

0

65,535

int32

Yes

32 bits (4 bytes)

-2,147,483,648

2,147,483,647

string

No

8 bits per character + 8 (1 byte + 1 byte)

N/A

N/A


Accessing Data

Similar to how the data section works, all indexes always begin at 0 within each row, meaning the first value is stored at 0. When you want to access the data within you do so using the below syntax:

Below you'll see a couple of examples of how this works:

Last updated