Talos docs

HudFieldOptions

Since 0.7

How one stock-HUD field reads (ctx.hud.set(field, value, options)).

Plain text

It applies from then on, until the field is set with options again. A scene's own meta.hud spec for the field wins over all three.

Signature

export interface HudFieldOptions {
  /** The label shown before the value, in place of the field's name ("Speed"). */
  label?: string
  /** Shown after a number ("km/h"). */
  unit?: string
  /** Fixed fractional digits for a number, a whole number 0..6 (the timer's tenths by default). */
  decimals?: number
}

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

Members

MemberSignatureDescription
labellabel?: stringThe label shown before the value, in place of the field's name ("Speed").
unitunit?: stringShown after a number ("km/h").
decimalsdecimals?: numberFixed fractional digits for a number, a whole number 0..6 (the timer's tenths by default).

Example

The tested fixture fixtures/app/noisy.ts.

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

// Calls into the Ctx surfaces this build records but does not yet act on: particles, HUD and
// labels. `tests/queues.rs` runs it to prove those recordings are bounded — a queue nobody
// drains has to be emptied each frame, or a behavior that emits every tick leaks.
export default {
  init(ctx) {
    ctx.state.ticks = 0
  },
  update(ctx) {
    const n = (ctx.state.ticks as number) + 1
    ctx.state.ticks = n
    ctx.particles.emit("dust", ctx.entity.position, { rate: 4 })
    ctx.hud.set("score", n)
    ctx.labels.set("here", "goal.hazard", ctx.entity.position)
    // A sound no asset registers: the one call above that the engine really cannot act on, so
    // `unwired` has something non-zero for the HTTP test to compare against.
    ctx.audio.play("no-such-sound")
  },
} satisfies Behavior