Persistent variables: PVAR and SPVAR
Store bounded settings in Zen global or slot-private persistent memory and load safe defaults.
Overview
Persistent variables preserve small settings beyond ordinary runtime state. PVAR positions are global; SPVAR positions are private to an individual slot.
Read with explicit bounds and a default so an absent or invalid stored value resolves safely. Avoid frequent writes when a setting has not changed.
Key facts
- Zen provides 16 global PVARs.
- Each slot provides 64 SPVARs.
- Across eight slots, Zen provides 512 private SPVAR positions.
- get_pvar requires a constant identifier plus minimum, maximum, and default values.
GPC syntax examples
Examples are intentionally small. Replace identifiers only with values documented for your target.
int sensitivity;
init {
sensitivity = get_pvar(SPVAR_1, 1, 100, 50);
}Functions, commands, and terms
Names below are catalog entries, not guessed signatures. Open the official sources for current parameter and return-value details.
get_pvarfunctionLoads a bounded persistent value using identifier, minimum, maximum, and default.
set_pvarfunctionStores a value in a persistent-variable position.
PVAR_*constant familySelects one of 16 global persistent positions.
SPVAR_*constant familySelects one of 64 private positions for the active slot.
Common mistakes
Calling get_pvar without min, max, and default.
Confusing a global PVAR with a slot-private SPVAR.
Writing on every main cycle when the value has not changed.
Official GPC sources
Use these first-party references to confirm exact syntax and runtime behavior for your installed firmware and Studio version.
Related GPC references
Understand signed 16-bit runtime values, global storage, local scope, initialization, and safe array indexing.
Executioninit and main execution modelKnow what runs once, what loops, and why blocking or one-time work belongs in the correct execution block.
ToolingCompiler errors and GPC debuggingDiagnose placement, identifier, type-range, combo-timing, and target-version problems systematically in Zen Studio.