Skip to content

Scoring

Scoring is just increment_state on a numeric key. The interesting part is when you increment.

Add a point when something happens — here, banking a chest at your ship:

- id: deposit_red
when:
kind: and
children:
- { kind: entered_zone, who: any, zoneId: red_ship }
- { kind: state_equals, who: same, key: carrying, value: true }
- { kind: compare, op: eq, left: { ref: same.teamId }, right: red }
do:
- { kind: set_state, target: same, key: carrying, value: false }
- { kind: increment_state, target: same, key: score, by: 1 }
- { kind: send_event, to: same, event: { type: toast, text: "Chest banked!" } }

Source: apps/wage-engine/src/games/pirates_booty/game.yaml.

Increment on a tick, gated by whatever must be true. King of the Hill scores the sole occupant of the hill, once per second:

- id: score_tick
when:
kind: and
children:
- { kind: state_equals, who: any, key: inHill, value: true } # binds same per occupant
- { kind: count_state, who: any, key: inHill, value: true, n: 1 } # exactly one
- { kind: state_equals, who: same, key: won, value: false }
- { kind: tick, everyMs: 1000 }
do:
- { kind: increment_state, target: same, key: score, by: 1 }

Source: apps/wage-engine/src/games/king_of_the_hill/game.yaml. Put the player-binding conditions before tick.

Target a whole team so any member’s action credits the team:

- { kind: increment_state, target: { byTeam: blue }, key: score, by: 1 }

When you later compare team totals (e.g. at countdown end), each player carries the team score; read it with { ref: "same.state.score" }.

  • Initialize the key in playerJoinStates ({ score: 0 }) so it’s never undefined.
  • increment_state treats missing/non-number as 0, and by can be negative (penalties, damage).
  • To end the game on a score, see Win conditions.