moxzi
Docs / moxzi.game / Saving and restoring

Saving and restoringpreview

How the player saves a game, what a save contains, and what your actor must do for restores to work.

The player saves the complete state of every game actor. You don't write save or load code: whatever is in your actor's variables when the game is saved is there when it's restored.

Save and restore#

moxzi-player out/drift native --save drift.save

The player writes the save periodically, when the app goes to the background, and when it exits. Start from a save with --restore:

moxzi-player out/drift native --restore drift.save

moxzi-game inspect-checkpoint FILE prints a summary of a save: its tick, the number of actors, and their memory size.

New game#

Players with a saved game see Save and New game buttons. New game asks for confirmation, then starts your game from moxzi_boot with a fresh actor. The previous save is kept as a backup until the next successful save.

What your actor must do#

Because the save is the actor's whole state, most games need no extra work. A few rules keep restores working:

RuleWhy
Store the time of the last tick and pass it to Render.empty in moxzi_snapshotThe player checks that the restored scene matches the restored clock. A mismatch stops the player with lifecycle acknowledgement disconnected
Keep everything that affects the game in actor variablesAnything else, such as values derived from the wall clock, won't be restored
Rebuild the full scene in moxzi_snapshot from the current stateAfter a restore the player calls it to draw the first frame

Sounds, the camera view the player has moved, and panel settings are not part of the save.

Compatibility#

A save can only be restored by the exact package that wrote it, on the same execution backend (native, pulley or aot). Rebuild your game and old saves are refused with an error; they aren't converted. Use a new save file for each build while developing.

Limitations#

LimitationWhat to do
Saves can't be migrated to a new buildPlan to start new games after an update
Save files are limited to 128 MiBKeep large, rebuildable data out of actor state
On this pageSave and restoreNew gameWhat your actor must doCompatibilityLimitations