> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/learn-gpc/runtime-variables.md).

# Runtime variables

GPC has one runtime variable type: the signed 32-bit integer, written as `int`. You can declare one value at a time or reserve a consecutive group of values as an array.

***

### Scalar integers

Use a scalar integer when a name needs to hold one value:

```cpp
int count;
int strength = 25;
int x, y, enabled;
```

Rules:

* Declarations are global and top-level only.
* Uninitialized variables start at zero.
* There is no runtime `bool`, float, string, object, struct, or local block variable type.
* Function parameters are local integer values.
* Arithmetic overflow wraps according to the VM's integer behavior; design ranges to avoid relying on overflow.
* Runtime division truncates: `10 / 3` is `3`, `3 / 4` is `0`.

***

Scaled-integer pattern:

{% code title="scaled-integer-pattern.gpc" %}

```cpp
// 125 means 1.25x; calculate percentage before dividing away precision.
int base = 40;
int scale_percent = 125;
int result;

main {
    result = (base * scale_percent) / 100;
}
```

{% endcode %}

Check that the multiplication cannot exceed the 32-bit range.

***

### Runtime arrays

Use an array when you need several related runtime values under one name:

{% code title="runtime-arrays.gpc" %}

```cpp
int samples[16];
int index;

main {
    if(event_press(PS5_CROSS)) {
        samples[index] = get_ival(PS5_RX);
        index = index + 1;
        if(index >= 16) index = 0;
    }
}
```

{% endcode %}

Runtime arrays:

* occupy one variable slot per element;
* start filled with zero;
* cannot have initializers;
* require an index in range `0..size-1`;
* can use constant or runtime indexes;
* are mutable.

The compiler catches constant out-of-range indexes on ordinary declared arrays. You must validate dynamic indexes yourself.

***

### Sequential variable storage and aliases

Runtime variables are allocated sequentially after any variable slots generated by the compiler. GPC's indexing syntax operates on those sequential slots, so any runtime variable can technically be used as the base of an indexed access—not only a name declared with `[size]`.

{% code title="sequential-alias.gpc" %}

```cpp
int first;
int second;

main {
    first[1] = 25; // accesses the next sequential slot: second
}
```

{% endcode %}

This is an advanced aliasing behavior, not a substitute for a properly declared array. It can silently reach an unrelated variable when declarations change, so use it only when the storage layout is intentional and documented.

***

A zero-sized array occupies no slots and aliases the next declared variable:

{% code title="zero-sized-alias.gpc" %}

```cpp
int alias[0];
int value;

main {
    alias[0] = 50; // writes value
}
```

{% endcode %}

The compiler warns about this accepted quirk. A zero-sized array with no eligible variable after it is an error because it would point beyond the allocated variable table.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/learn-gpc/runtime-variables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
