Variables & Types

Data Types

Integer Types

gpc
int value = -100;        // 32-bit signed (-2B to 2B)
uint counter = 500;      // 32-bit unsigned (0 to 4B)
int8 small = -50;        // 8-bit signed (-128 to 127)
uint8 byte = 255;        // 8-bit unsigned (0 to 255)
int16 medium = -10000;   // 16-bit signed (-32K to 32K)
uint16 word = 60000;     // 16-bit unsigned (0 to 65K)
int32 large = -1000000;  // 32-bit signed (alias for int)
uint32 big = 4000000000; // 32-bit unsigned (alias for uint)

For compatible scripts, char maps to int8, long maps to int32, accum maps to fix32, and unsigned char, unsigned int, and unsigned long map to the matching unsigned types.

Fixed-Point Type

gpc
fix32 decimal = 3.14159;     // 16.16 fixed-point format
fix32 multiplier = 1.5;
fix32 negative = -0.75;

Fixed-point numbers provide decimal precision without floating-point overhead. Range: -32768.0 to 32767.99998

Boolean Type

gpc
bool enabled = TRUE;
bool active = FALSE;

Boolean values are TRUE (1) or FALSE (0).


Variable Declaration

Global Variables

Declared outside any block, accessible everywhere:

gpc
int global_counter = 0;
fix32 sensitivity = 1.0;

main {
    global_counter++;
}

Local Variables

Declared inside blocks, scoped to that block:

gpc
main {
    int local_value = get_val(BUTTON_10);
    
    if (local_value > 50) {
        int inner = local_value * 2;  // Only visible inside if
    }
}

Arrays

Fixed-size collections of same-type elements:

gpc
int scores[10];          // Array of 10 integers
fix32 multipliers[4];    // Array of 4 fix32 values
int8 buttons[17];        // Array of 17 bytes

Array Access:

gpc
int values[5];

main {
    values[0] = 100;
    values[1] = 200;
    
    int sum = values[0] + values[1];
    
    for (int i = 0; i < 5; i++) {
        values[i] = i * 10;
    }
}

Type Conversions

Implicit Conversions

  • int โ†” uint (automatic)
  • int/uint โ†’ fix32 (automatic)
  • Any numeric type โ†’ bool (0 = FALSE, non-zero = TRUE)

Explicit Casts

gpc
fix32 decimal = 3.75;
int whole = (int)decimal;      // Result: 3

int value = 100;
fix32 precise = (fix32)value;  // Result: 100.0

Constants

Use #define for compile-time constants:

gpc
#define TEST_BUTTON BUTTON_15
#define TEST_HOLD_MS 100
#define SENSITIVITY 1.5

int diagnostic_runs = 0;

combo OutputTest {
    set_val(TEST_BUTTON, 100);
    wait(TEST_HOLD_MS);
    set_val(TEST_BUTTON, 0);
}

Initialization

Variables can be initialized at declaration:

gpc
int x = 0;
fix32 z = 1.5 + 0.5;      // Expression
bool flag = TRUE;

Uninitialized global variables default to 0. Put runtime reads like get_val() inside init, main, a combo, or a function body.