keyword
handler
handler Name phase P { … }
A handler is a named block of behavior that the engine runs automatically during a given phase — the unit that turns your data into a game. A handler with no query runs once per phase tick; a handler with a @Queries annotation (or an inline for (…) in query […] loop) runs its body once per matching model instance, with each property bound by name and self() giving the current instance. Handlers are registered implicitly just by being declared, and you can pause one at runtime with disable Handler and bring it back with enable Handler. Keep behavior in handlers and keep data plain in properties — that separation is the whole point.
Example
program Runner {
property Position { column: int = 0, row: int = 0 }
property Velocity { delta_x: int = 0, delta_y: int = 0 }
model Player { Position, Velocity }
handler Boot phase Start {
spawn Hero { Position { column: 0, row: 6 }; Velocity { delta_x: 1 } }
}
handler AdvancePositions phase Update {
for (position, velocity) in query [Position, Velocity, {Player}] {
position.column = position.column + velocity.delta_x
}
}
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
for (position) in query [Position, {Player}] {
Screen.fill_rectangle(x: position.column * 16, y: position.row * 16, width: 16, height: 16, color: Color.LimeGreen)
}
Screen.show()
}
}