Rûn Events: Where Scripts Run
A script does nothing until something calls it. This page lists what calls scripts, which file answers a call, and what is different between the editor and a running game.
What calls a script
Each caller names a script and a section. The script is found by name; the section is [use] in an event script or on use { } in a program.
- A prop, used
- The use key (E) next to an interactable prop runs its event's
usesection; a locked door runslocked; a breakable that breaks runsdestroy. See Events and Triggers. - A zone
- Walking in runs
enter, walking out runsexit. - A villager
- A conversation starting runs the talk event's
talk; a killable villager's death runskilled. - A map
- The script named like the map runs
loadwhen the map opens in play. - A controller
- Its event's
runsection, or its first section with a line, at map start, on a condition or on a timer. - A random event
- An outcome of kind
scriptruns that script'srandomsection. - The fall
- The scripts named
deathandrespawnrun theirdeathandrespawnsections. - A key of your own
- A custom action runs the section the
action eventverb links to it. - Another script
run <name> [section]in an event script, which runs an event script of that name, or a program when there is none;World.Fire("<name>", "<section>")in a program.- The console
run <name> [section]runs an event script;World.Fire("<name>", "<section>")runs any script, a program included.
A section that does not exist is skipped without a word, so a zone script with only enter is fine when she walks out again.
Which file answers
When the world calls a name (a prop, a zone, a villager, a controller, World.Fire, the console), the engine looks in this order, and the first file found answers:
assets/scripts/<name>.run, a program. Itson <section>block runs.assets/events/<name>.runwritten with braces, a block script.assets/events/<name>.run, or the older.evtand.rune, an event script.
So a program may take over an event by name: write assets/scripts/barn_door.run with an on use block and the barn door runs the program instead of assets/events/barn_door.run. An event script's own run line looks the other way round: an event script of that name first, then a program.
// assets/scripts/ev_luck.run
on use {
World.FlagSet("ev_luck_ran")
}# assets/events/ev_caller.run
[use]
run ev_luck
if flag(ev_luck_ran)
say The program ran.The program ran.The checker knows a program's name, so such a run line checks clean.
Sections in each kind
# assets/events/ev_door.run
[use]
say The door creaks open.
flag set ev_door_open
[locked]
say It will not budge.The door creaks open.// assets/scripts/ev_door_program.run
on use {
World.FlagSet("ev_door_open")
print("the program opened the door")
}
on locked {
print("still locked")
}the program opened the doorWhen a program's section runs, only that block runs: the program's top level is not run first (see Rûn Variables and Scope). A program with no section of the name called is silent, like an event script.
Every frame: on update
A program with an on update(number dt) block is a live program. During a play, the engine reads it once, runs its top level once, and then runs the update block every frame with dt, the frame's length in seconds. Its variables are kept between frames, and its other sections and rule blocks run with the same variables.
// counts the seconds of play; used, it raises a flag once time has passed
number seconds = 0
on update(number dt) {
seconds = seconds + dt
}
on use {
if (seconds > 0) World.FlagSet("ev_time_passed")
}In Test mode, a few frames after the play begins:
World.Fire("ev_heartbeat", "use")
print(World.Flag("ev_time_passed"))onThe use section saw the seconds the update block had been adding to, frame after frame.
A live program is dropped when the play ends; the next play reads it again from the top. In the editor its update block does not run.
Scenes: block scripts
A block script in assets/events is written with braces and runs its lines one after another, each finishing before the next starts, with Simul { } for things that happen at once. It is the kind for cutscenes. See Block Scripts and Cutscenes.
Begin Event "ev_scene" on use {
Player.LockMovement
Camera.Zoom (2) over 1s
Wait 1s
Camera.Zoom (1) over 1s
Player.UnlockMovement
}In the editor and in play
Event scripts and programs both run in the editor, from the console. What needs a running game refuses in the editor and says so: giving her an item, moving the camera, spawning a foe. Readings (Player.Count, World.Flag, count(<item>)) work in both. An event script's wait and the later lines of a block script run only while the game runs.
Player.Give("ev_nothing", 1)needs a running game