For the complete documentation index, see llms.txt. This page is also available as Markdown.

SPVAR storage

Ownership

SPVAR_1..SPVAR_64 are private to the current Zen memory slot and are the normal choice for per-script settings. Pass an SPVAR_* selector to the supported get_pvar and set_pvar built-ins.


Validated load

spvar-validated-load.gpc
int strength;
int mode;

init {
    strength = get_pvar(SPVAR_1, 0, 100, 25);
    mode = get_pvar(SPVAR_2, 0, 3, 0);
}

get_pvar(slot, min, max, default) returns the default when stored data is outside the range. Pick a range that actually validates the field.


Event-driven save

spvar-event-driven-save.gpc
int strength = 25;
int settings_dirty;

main {
    if(event_press(PS5_UP)) {
        strength = strength + 1;
        if(strength > 100) strength = 100;
        settings_dirty = TRUE;
    }

    if(settings_dirty && event_press(PS5_OPTIONS)) {
        set_pvar(SPVAR_1, strength);
        settings_dirty = FALSE;
    }
}

Do not put set_pvar at base level in main. Save only after a deliberate state change/save action.

Last updated