# GameEvent

> Talos next · Since 0.6

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

## Signature

```ts
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

| Member | Signature | Description |
|---|---|---|
| `name` | `name: string` |  |
| `data` | `data: T` | Whatever was passed to `emit`, JSON round-tripped. |
| `by` | `by: string \| null` | Id 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`.

```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>
```
