Const Arrays
Const arrays are basically compiler-managed lists of data stored in the data section.
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 value.
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 |
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: