Website logo
Cronus ShopGamePacksForumsDiscordYouTube
📘Cronus Zen Guide
📗GamePacks
📗GPC Script Guide
Navigate through spaces
⌘K
👋GPC: An Introduction
🚀New 32-bit Updates
📑GPC Developer Guides
Basic Syntax
Basic GPC Structure
A Simple Tutorial
Variables
Definitions
Data Section
Remapping
Const Arrays
Init Section
Main Section
Combo Section
User Created Functions
Identifiers
Flow Control
Operator Types
Constants
Functions
Device Functions
Remapping
Advanced Samples
API Samples
Docs powered by Archbee
GPC Developer Guides

Const Arrays

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

Syntax

GPC
const <datatype> <name>[] { <values> }; // Single dimensional
const <datatype> <name>[][] = { { <values for the first "row"> }, { <values for the second "row"> } }; // Two dimensional


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 536

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:

GPC
name[column];

GPC
name[row][column];


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

GPC
const int8 single_dimension[] = { 0, 1, 2 };
const uint8 multi_dimension[][] = { { 0, 1, 2 }, { 3, 4, 5 } };

int a, b;
main {
    a = single_dimension[1]; // 1
    b = multi_dimension[1][2]; // 5
}




PREVIOUS
Remapping
NEXT
Init Section
Docs powered by Archbee
TABLE OF CONTENTS
Syntax
Accessing data
Docs powered by Archbee