Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

PluginSave

A save as the session reads it, in the one scope the game keeps it in: what each owner of a record holds, the engine’s own saves included.

Type Parameter Default type
Schema extends SaveSchema SaveSchema
Scope extends SaveScopeName SaveScopeName
Property Type Description
migrations? Readonly<Record<number, (saved) => unknown>> One step per version: step 2 turns a version 1 state into version 2. A pure function from old JSON to new JSON.
schema Schema Checks every state loaded, after its steps, and types restore’s.
scope Scope Where the state is read from and restored onto: the player entity, each saved entity by the name it is saved as, or the world.
version number Counts the shape of the state. Any change to the shape raises it, an added optional field included, and adds a step.
with? readonly SaveTrait[] The traits a saved entity holds for the save to keep its state on it, as defineSave’s with says.

read(context): input<Schema>

What to keep, as plain JSON: synchronous, and changing nothing. A value its schema or JSON would refuse refuses the whole read.

Parameter Type
context SaveContext<Scope>

input<Schema>


restore(context, saved): void

Puts a loaded state back: a player’s after every onPlayerJoin and before any onPlayerReady, a saved entity’s as setSavedEntity registers it, over what its spawn set up, or after the player’s where a join hook registered it. The world’s state restores as the record loads. A throw refuses the load.

Parameter Type
context RestoreContext<Scope>
saved output<Schema>

void