Save/Load Demo
App: apps/save_load_demo/
Demonstrates game-authored, versioned save/load (engine PLM-022 / ADR 0036). On every launch it reads a save slot, increments a persisted launch counter, and writes it back — so quitting and re-running the app makes the counter climb, proving the state survives across runs. A small GUI window shows the current count and lets you re-save on demand.
Run from root
Section titled “Run from root”% ./plume3d save_load_demoRe-run it a few times and watch the launch count go up. The save lands at
saves/demo.sav under the app’s own directory (the write dir).
What it does
Section titled “What it does”- On
init, reads the slot withSave.read("saves/demo.sav"). If it returnsnull(no save yet, or a save from a newer build), it starts fresh at launch 1; otherwise it reads the previouslaunchesvalue withloaded.getInt("launches", 0)and adds one. - Rebuilds a fresh
SaveStatefrom the current game state — an intlaunches, a stringplayer, a booltutorialDone, and a numbervolume— and persists it withSave.write(_slot, s), latching a status message on success or failure. This is the game-authored model: the app writes exactly the keys it cares about, not an automatic scene dump. - Persists immediately on launch, and again whenever you press S, so you can re-save without waiting for the next run.
- Draws a small Gui window showing the persisted launch count, the last status message, and the hint to quit and re-run.
Key pattern
Section titled “Key pattern”import "engine" for Save, SaveState
// Read (or start fresh), increment, write back — the persist-across-runs loop.var loaded = Save.read("saves/demo.sav")var launches = (loaded == null) ? 1 : loaded.getInt("launches", 0) + 1
var s = SaveState.new()s.setInt("launches", launches)s.setString("player", "Ada")s.setBool("tutorialDone", launches > 1)s.setNumber("volume", 0.8)Save.write("saves/demo.sav", s) // -> true on successSave.read returning null is the same signal for “no save yet” and “save is from a
newer engine build” — a newer-format file is rejected, never mis-parsed — so guarding the
read against null is all the version-safety the game needs.
- Save / Load —
SaveState.new,setInt/setString/setBool/setNumber,getInt,count;Save.write,Save.read. - Gui — the status window (
beginWindow,label,layoutRowDynamic). - Input —
keyJustPressedfor the re-save key. - Logger —
info.