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

defineLiveState

defineLiveState<Name, Schema>(name, liveStateOptions): LiveStateHandle<Name, Schema>

Declares one of the game’s live states, at module scope in src/liveState.ts, which the room’s scene exports too: a few named states, such as "events" and "weather", at most 8, each a JSON document of 1 KiB at most that every room and page of the game reads. Throws for a name that is not kebab-case and an initial state the schema refuses; spawnite build refuses a schema a snapshot cannot say whole.

Type Parameter
Name extends string
Schema extends ZodMiniType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Parameter Type
name Name
liveStateOptions LiveStateOptions<Schema>

LiveStateHandle<Name, Schema>

export const events = defineLiveState("events", {
schema: z.object({ doubleCoins: z.boolean() }),
initial: { doubleCoins: false },
});