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

PluginSave

What a plugin keeps in a player’s save, through definePlugin’s save: a kit’s under kits.<name>, on once the game lists the kit; an engine plugin’s under engine.<name>, off until the game names it in include.

Type Parameter Default type
Schema extends SaveSchema SaveSchema
Scope extends SaveScopeName SaveScopeName
Property Type Default value Description
migrations? Readonly<Record<number, (saved) => unknown>> undefined 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 undefined Checks every state loaded, after its steps, and types restore’s.
scope? Scope "player" Where the state is read from and restored onto: her player entity, each saved entity under its key, or the world, a page game’s alone.
version number undefined Counts the shape of the state. Any change to the shape raises it, an added optional field included, and adds a step.

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, and the world’s as the record loads. A throw refuses the load.

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

void