Talos docs

GameEvent

Since 0.6

A game event as delivered to onEvent and to events.on handlers.

Plain text

Signature

export interface GameEvent<T = unknown> {
  name: string
  /** Whatever was passed to `emit`, JSON round-tripped. */
  data: T
  /** Id of the emitting entity, or null for events raised by the engine or the app. */
  by: string | null
}

Import: import type { GameEvent } from "@argus/api"

Members

MemberSignatureDescription
namename: string
datadata: TWhatever was passed to emit, JSON round-tripped.
byby: string | nullId of the emitting entity, or null for events raised by the engine or the app.

Example

The tested fixture fixtures/recipes/many-entities/scenes/behaviors/beacon.ts.

import type { Behavior } from "@argus/api"

/** A beacon: counts the drones that touch it. Only this beacon hears its touches (`emitTo`). */
interface State {
  touches: number
}

export default {
  init(ctx) {
    ctx.state.touches ??= 0
  },
  onEvent(ctx, ev) {
    if (ev.name === "touched") ctx.state.touches += 1
  },
} satisfies Behavior<State>