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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Name extends string |
Schema extends ZodMiniType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
Name |
liveStateOptions |
LiveStateOptions<Schema> |
Returns
Section titled “Returns”LiveStateHandle<Name, Schema>
Example
Section titled “Example”export const events = defineLiveState("events", { schema: z.object({ doubleCoins: z.boolean() }), initial: { doubleCoins: false },});