> 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/data-and-persistence/bvar-storage.md).

# BVAR storage

Cronus Zen provides 1,024 BVAR entries, indexed `0..1023`. Use `get_bvar(index)` to read one entry and `set_bvar(index, value)` to write one. Each entry stores a signed 16-bit word (`-32768..32767`), so validate or clamp a runtime value before writing it instead of assuming the runtime integer's wider range will persist.

{% code title="bvar-edit-value.gpc" %}

```cpp
int edit_value;

main {
    if(event_press(PS5_CROSS)) {
        edit_value = -75;
        set_bvar(120, edit_value);
    }

    if(event_press(PS5_OPTIONS)) edit_value = get_bvar(120);
    set_val(TRACE_1, edit_value);
}
```

{% endcode %}

Keep BVAR writes behind explicit edit/save events rather than the base of `main`. Read a record during initialization, profile changes, or another deliberate cache refresh instead of rescanning the complete store every cycle.

Do not scatter numeric BVAR indexes. Define a schema:

```cpp
define BVAR_SCHEMA_VERSION = 1;
define BVAR_HEADER_BASE = 0;
define BVAR_RECORD_BASE = 16;
define BVAR_RECORD_STRIDE = 8;
define BVAR_FIELD_ID = 0;
define BVAR_FIELD_LENGTH = 1;
define BVAR_FIELD_X = 2;
define BVAR_FIELD_Y = 3;
```

For record index `r`, compute:

```
base = BVAR_RECORD_BASE + r * BVAR_RECORD_STRIDE
field_index = base + BVAR_FIELD_*
```

Validate every computed index against `0..1023` and make the maximum record count a compile-time constant.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/data-and-persistence/bvar-storage.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
