Keep a score
Your rules count the score (settings.score). presetScore() gives every engine stat; defineStat adds your own. The screen shows it at the end and from the pause menu.
ts
// in src/rules.ts
import { defineIds, defineStat, entityDied, type Rules, presetScore, scoreOn } from '@v12-engine/engine'
const UNIT = defineIds('scout')
// one more for the owner of each guard tower lost
const towersLost = defineStat({ id: 'towersLost', label: 'Towers lost',
category: 'units',
from: scoreOn(entityDied, ({ entity }) => (entity.def.id === 'guardTower' ? entity.owner : undefined)) })
// the most gates held at once, with a point on the graph every 10 seconds
const gatesHeld = defineStat({ id: 'gatesHeld', label: 'Gates held', category: 'glory', kind: 'max', timeline: true })
export const rules: Rules = {
id: 'my-game',
name: 'My game',
units: [{ id: UNIT.scout, name: 'Scout', kind: 'unit', radius: 0.4, sight: 10, stats: { health: 100, moveSpeed: 5 } }],
settings: { score: presetScore({ without: ['army'], stats: [towersLost, gatesHeld] }) }
}Done: the end screen shows every stat but army size, plus Towers lost and Gates held.
Count a stat in code
ts
world.score.add(player, 'gatesHeld', 3)
world.score.get(player, 'gatesHeld')Reference
| Where | Call |
|---|---|
| Rules | world.score.add(player, id, n), world.score.get(player, id) |
| Screen | client.score.get(player, id), client.score.show('glory') |
| Look | GameView.hud.score: labels, formats, graph stats, hidden tabs, open at the end |
| Who sees what | live: allies by default, everyone once the game is decided |
The debug panel's Score window shows every stat live. See The score.