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

defineEvent

defineEvent(name): EventHandle<NoRecord, Reliable, Entity>

Makes an event under name, which the log, the dump, the devtools and a room’s stream know it by: defineEvent("damaged", { amount: 0, at: new Vector3() }). The record is its fields’ defaults, or a function that makes them; with none, or one with no field, the event carries no record. Each emit is one event, read once by each system and heard once by each view that listens, in the order emitted. Called once, at module scope, in a module the room and the page both import.

Parameter Type
name string

EventHandle<NoRecord, Reliable, Entity>

defineEvent<Replication, Scope>(name, schema, options): EventHandle<NoRecord, Replication, Scope>

Makes an event under name, which the log, the dump, the devtools and a room’s stream know it by: defineEvent("damaged", { amount: 0, at: new Vector3() }). The record is its fields’ defaults, or a function that makes them; with none, or one with no field, the event carries no record. Each emit is one event, read once by each system and heard once by each view that listens, in the order emitted. Called once, at module scope, in a module the room and the page both import.

Type Parameter Default type
Replication extends EventReplication Reliable
Scope extends EventScope Entity
Parameter Type
name string
schema undefined
options Pick<EventOptions<NoRecord, Replication, Scope>, "replication" | "scope">

EventHandle<NoRecord, Replication, Scope>

defineEvent<Schema, Replication, Scope>(name, schema, …options): EventHandle<RecordOf<Schema>, Replication, Scope>

Makes an event under name, which the log, the dump, the devtools and a room’s stream know it by: defineEvent("damaged", { amount: 0, at: new Vector3() }). The record is its fields’ defaults, or a function that makes them; with none, or one with no field, the event carries no record. Each emit is one event, read once by each system and heard once by each view that listens, in the order emitted. Called once, at module scope, in a module the room and the page both import.

Type Parameter Default type
Schema extends object -
Replication extends EventReplication Reliable
Scope extends EventScope Entity
Parameter Type
name string
schema Schema
…options RequiredWhereEntities<RecordOf<Schema>, EventOptions<RecordOf<Schema>, Replication, Scope>>

EventHandle<RecordOf<Schema>, Replication, Scope>