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, her player entity and each saved entity, and read back from them.

Property Modifier Type Description
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 Entity | undefined Her player entity, once attachPlayer named it.

attachPlayer(player): void

Restores the player-scope saves onto her player entity, after every onPlayerJoin, reads them from her from then on, and makes this the session setSavedEntity restores her saved entities from. A restore that throws refuses the load, as load does.

Parameter Type
player Entity

void


captureEntity(entity, key): SaveRead

Reads entity’s entity-scope saves into the record under key, as it goes: a copy, since the entity is about to change or be destroyed. Where one owner’s read fails, keeps the key’s record as it was and hands out the problem.

Parameter Type
entity Entity
key string

SaveRead


capturePlayer(): SaveRead

Reads her player-scope saves and each of her saved entities into the record, as her 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): 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

SaveLoad


read(): SaveRead | null

Reads every owner into the record and hands it out, each key no owner claims kept, and each saved-entity key 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.

SaveRead | null


restoreEntity(entity, key): boolean

Restores the record kept under key 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
key string

boolean