Memory & Persistent Data

Use memory helpers for arrays and pmem to save and reload small settings during a script run. In Helios, these values do not survive a script reload or application restart.

Memory Helpers

gpc
memset(&destination, value, size);
memcpy(&destination, &source, size);
gpc
uint8 source[4];
uint8 copy[4];

init {
    source[0] = 10;
    source[1] = 20;
    source[2] = 30;
    source[3] = 40;
    memset(&copy, 0, sizeof(copy));
    memcpy(&copy, &source, sizeof(source));
}

Both calls return a status value. Keep the requested size inside the referenced variable or array.

Persistent Memory

Function Use
pmem_load() / pmem_load(slot) Load the default or selected save slot
pmem_save() / pmem_save(slot) Save the current persistent-memory image
pmem_read(offset) Read one unsigned byte
pmem_read(offset, &variable) Read a typed value
pmem_write(offset, value) Write a value using its declared type

GPC3 provides a default slot and nine numbered slots, each with 128 bytes. Use pmem_load() / pmem_save() for the default slot, or pass a slot from 1 through 9. Explicit slot 0 is invalid. Load before reading and save after writing.

gpc
int sensitivity = 100;

init {
    pmem_load();
    pmem_read(0, &sensitivity);

    if (sensitivity < 50 || sensitivity > 150) {
        sensitivity = 100;
    }
}

main {
    if (event_active(BUTTON_5)) {
        sensitivity = min(sensitivity + 5, 150);
        pmem_write(0, sensitivity);
        pmem_save();
    }
}

Notes

  • Keep a simple offset list at the top of the script.
  • Do not let values overlap in the 128-byte slot.
  • Validate loaded values before using them.
  • Save only when a setting changes rather than on every main iteration.