1.4 KiB
1.4 KiB
| id | name | category | kind | tokens | sig | tip | order |
|---|---|---|---|---|---|---|---|
| kw-enter | enter | scenes | keyword | enter | on enter { … } | The scene-entry hook — runs once as a scene becomes active. | 3 |
enter names the body of a scene's entry hook, written on enter { … }. It runs once each time the scene becomes active — at boot for the start scene (right after the Start phase), and on every become Name that switches into it. This is where a scene builds what it owns: spawn its models, reset its counters, set the tilemap, open a menu. It is a lifecycle hook, not a phase, so it may not contain phase handlers; the scene's ongoing behaviour goes in its layer handlers instead.
program EnterHookExample {
property Position { column: int = 0, row: int = 0 }
model Player { Position }
state EnterHookExampleState {
score: int = 0
}
scene Overworld start {
on enter (enter_hook_example_st: mut EnterHookExampleState) {
enter_hook_example_st.score = 0
spawn Player { Position { column: 5, row: 5 } }
}
layer World {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
for (current_position) in query [Position, {Player}] {
Screen.fill_rectangle(x: current_position.column * 16, y: current_position.row * 16, width: 16, height: 16, color: Color.LimeGreen)
}
Screen.show()
}
}
}
}