keyword
var
var name: T = value
A var declares a mutable binding: unlike let, you may reassign it later with =, +=, -=, and friends. Where it appears decides its lifetime — inside a handler or function body it is a local, and at program scope it is persistent, named game state that every handler shares. Program-scope vars are the modern replacement for numeric registers: instead of reg(0), you write var score: int = 0 and read and write score by name. Use var for anything that genuinely changes — accumulators, the current score, a mode flag, an elapsed-frame counter — and prefer let for values that never change.
Example
program Scorekeeper {
var score: int = 0
var elapsed_frames: int = 0
handler Tick phase Update {
elapsed_frames = elapsed_frames + 1
if elapsed_frames % 60 == 0 { score = score + 1 }
}
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.draw_text(x: 6, y: 4, text: "SCORE", color: Color.White, scale: 1)
Screen.draw_number(x: 52, y: 4, value: score, color: Color.Gold, scale: 1)
Screen.show()
}
}