VaelisDocs
v1.0.0
Scripting · v1.0.0

Persistence

Use transient global state and durable IndexedDB saves.

View as Markdownllms.txt

#global vs save

SurfaceLifetime
globalTransient cross-script state for the current play session/page. Refreshing the page clears it.
savePersistent per-slot key/value storage backed by IndexedDB. Survives refresh/reopen when browser storage is available.

#Basic save API

js
save.set("score", 1250);
const score = save.get("score");

if (!save.has("tutorialSeen")) {
  save.set("tutorialSeen", true);
}

#Multiple save slots

js
await save.load("slot2");
const hp = save.get("targetHp");

const slots = await save.listSlots();

#Flush before a transition

js
async function onGameComplete() {
  save.set("completed", true);
  await save.flushNow();
  scene.load("Credits");
}

#Storage errors

save.set() updates the in-memory value synchronously while IndexedDB writes happen in the background. Register save.onError(fn) to observe persistent-storage failures such as quota errors or unavailable IndexedDB implementations.