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

readLiveState

readLiveState<Schema>(world, handle): LiveStateResult<ReadonlyLiveState<output<Schema>>>

Reads a live state as the room last applied it, in a room and on its pages alike: its state, its revision, and whether it changed on this tick. Before the first write, and in a game no room runs, the initial state at revision 0. The state is frozen: every reader shares it, so write a new one with setLiveState.

Type Parameter
Schema extends ZodMiniType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Parameter Type
world World
handle LiveStateHandle<string, Schema>

LiveStateResult<ReadonlyLiveState<output<Schema>>>

const { state, wasChanged } = readLiveState(world, events);
if (wasChanged && state.doubleCoins) showBanner();