Talos docs

Batch

Since 0.7

The instances an updateAll steps: index k is one instance, the same k in each list.

Plain text

Signature

export interface Batch<S = Record<string, any>> {
  /** How many instances. */
  readonly count: number
  /** Each instance's entity, a fresh handle every tick: compare with `id`, not `===`. */
  readonly entities: readonly EntityHandle[]
  /** Each instance's own `ctx.state`. */
  readonly states: readonly S[]
}

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

Members

MemberSignatureDescription
countreadonly count: numberHow many instances.
entitiesreadonly entities: readonly EntityHandle[]Each instance's entity, a fresh handle every tick: compare with id, not ===.
statesreadonly states: readonly S[]Each instance's own ctx.state.

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>