Fire an event
event.fire("enemy_killed", enemy)
The first argument is the event name. Later arguments are values sent with it.
Receive an event
on enemy_killed(enemy) {
debug.log("Enemy defeated:", enemy.name())
}
The handler's name must match the fired event. Events are queued; do not treat event.fire() as a direct function call with a return value.
Event arguments
Pass the values the handler needs. Keep their order the same.
event.fire("score_changed", 25)
on score_changed(amount) {
debug.log("New score:", amount)
}
Contact events
An on_touch callback receives the touching object. It is not limited to the Player.
coin.on_touch = fn(thing) {
const player_entity = get_entity("Player")
if thing != player_entity {
return
}
coin.visible = false
coin.solid = false
}
This fragment assumes coin is already a valid object handle. See Finding Objects. Entity contact callbacks run when contact begins, not on every physics step while contact continues.
Other events
See Input for key presses and Actor navigation for route completion. The Events reference lists call signatures and callback arguments.