pmem - Kyuchumimo/Micro-Joy-Home-Video-Computer GitHub Wiki

🧩🧠 This is a general-purpose memory-related function.
🧩 This function depends on json MicroPython built-in module.

pmem index -> val32 Retrieve value from persistent memory file

pmem index val32 -> prior_val32 Save new value to persistent memory file, retrieve prior value.

Parameters

  • index : an index (0..255) into the persistent memory file.
  • val32 : the 32-bit integer value you want to store. Omit this parameter to read vs write.

Returns

  • val32 : the current/prior value saved to the specified memory slot.

Description

This function allows you to save and retrieve data in one of 256 individual 32-bit slots available in the file's persistent memory. This is useful for saving high-scores, level advancement or achievements. Data is stored as unsigned 32-bit integers (from 0 to 4294967295).

When writing a new value, the previous value is returned.

Memory Persistence

  • ⚠️ pmem depends on the SAVEID string. By default, this string is empty, so if you try to save a value without having declared SAVEID, the software will crash and throw an error.