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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Schema extends ZodMiniType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
world |
World |
handle |
LiveStateHandle<string, Schema> |
Returns
Section titled “Returns”LiveStateResult<ReadonlyLiveState<output<Schema>>>
Example
Section titled “Example”const { state, wasChanged } = readLiveState(world, events);if (wasChanged && state.doubleCoins) showBanner();