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

SaveSession

One player’s save in a world: the record as it stands, restored onto the world, the player entity and each saved entity, and read back from them.

Property Modifier Type Description
each? readonly EachRecords A world’s record’s per-entity records, where the game lists worldSaves: a room cuts them at each checkpoint, apart from read.
loaded readonly SaveLoad | null The last load, or the refusal of a restore after it; null until a record, or none for a new game, has loaded.
owners readonly readonly SaveOwner[] The owners of the record, in the order they restore.
player readonly PlayerEntity | undefined The player entity, once attachPlayer named it.
worldSaveBytes readonly ReadonlyMap<string, number> Each world save’s value as JSON, in UTF-8 bytes, by its key, as the last read measured it: each is held to maxWorldSaveBytes. Empty where the session keeps no world save.

attachPlayer(player, writer): void

Restores the player-scope saves onto the player entity, after every onPlayerJoin, then each saved entity of the player’s registered before it that asked for its record, as a join hook registers one. Reads them from the player from then on, and makes this the session setSavedEntity restores the player’s saved entities from. A restore that throws refuses the load, as load does, and restores nothing after it.

Parameter Type
player PlayerEntity
writer Authority | JoinStep

void


captureEntity(entity, savedAs): SaveRead

Reads entity’s entity-scope saves into the record for savedAs, as it goes: a copy, since the entity is about to change or be destroyed. Reads nothing of one whose record still waits to restore. Where one owner’s read fails, keeps the name’s record as it was and hands out the problem.

Parameter Type
entity Entity
savedAs string

SaveRead


capturePlayer(): SaveRead

Reads the player-scope saves and each of the player’s saved entities into the record, as the player goes: copies, as captureEntity makes. Where one owner’s read fails, keeps the record as it was and hands out the problem.

SaveRead


load(value, options?): SaveLoad

Loads a stored record, or none for a new game: each owner’s key is migrated and checked, in each saved entity’s record too, and the world-scope saves are restored. A record that fails, or a restore that throws, refuses the load: nothing more is restored, and nothing is written from then on.

Parameter Type
value unknown
options? SaveLoadOptions

SaveLoad


measureWorldSaves(): ReadonlyMap<string, number> | null

Reads each world save now and measures it, as worldSaveBytes, writing nothing into the record: what development checks once a second. Null where a read failed, which read reports.

ReadonlyMap<string, number> | null


read(this): SaveRead | null

Reads every owner into the record and hands it out, each key no owner claims kept, and each name with no live saved entity kept as it was last captured or loaded. Where one owner’s read fails, hands out its problem and keeps the record as the last good read left it. Null before a load and after a refused one, since nothing may be written then. The record holds what each read returned, not a copy: turn it into JSON before the game changes again.

Parameter Type
this void

SaveRead | null


restoreEntity(entity, savedAs, writer): boolean

Restores the record kept for savedAs onto entity, the entity-scope saves in order, over what its spawn set up. Answers false where a restore threw, which refuses the load; a session with no load, or one refused before, restores nothing and answers true. setSavedEntity calls it.

Parameter Type
entity Entity
savedAs string
writer Authority | JoinStep

boolean