Events and Triggers
An event is a named script that the world calls. This page covers the things that call them.
Zones
A zone is a rectangle on the map that runs its event's [enter] section when the player walks in and [exit] when she walks out. Outliner > Add… > Zone sets a square one in the middle of the view, already selected; drag it into place. Or open the Zones page of Edit > Project Settings (under EVENTS), press Draw on its Draw New Zone row, and drag a rectangle on the map. Zones are drawn in cyan, so they are never mistaken for spawn zones (amber).
A zone's name is its event's name. The first zone on a map is zone_1, the next zone_2, and so on. On the Zones page, pick a zone and its Event list points it at another event script, Rename renames it, Edit file opens its script (writing one if there is none), Logic opens the event gizmo, and Delete zone removes it. To move a zone that is not selected, click it once to select it, then drag it.
A zone fires for the player alone until you say otherwise: zone who <zone> enemy makes enemies set it off, and type <type>, tag <tag>, companion and anybody work the same way. In the zone's script, {zonewho} names who walked in.
Tagged props
A prop runs an event when the player walks up to it and presses the use key, once its Properties have Interactable > Interactable on and Interactable > Event names the event: that event's [use] section runs. With Event left on None, the event named like the prop's tag runs, and the list's first row says so: None: barn_door (Tag). The list ends with New, which makes an event named like the tag (or event_N) with its [use] section waiting and opens it; Edit File under the list opens the picked event. Set the tag with right-click > Edit Tag, or in Properties > Object. A breakable prop that breaks runs [destroy]. Maps and Travel walks through a door to another map step by step.
What an event list shows
Every event list in the editor (a prop's and a controller's Event, a zone's Event, an enemy type's On death, On spawn and On notice) names each event with the section that place would run: chest_open [use]. An event without that section shows (no [use]) when the place runs that section only, or (empty) when no section holds a line, and a name saved with no file behind it shows (Not found). A section the list names runs; one it does not name would not.
Villagers
A villager's Talk event runs [talk] when a conversation starts, and [killed] when a killable villager dies (see NPCs and Dialog).
Controllers
A controller is an object with no picture that runs an event while the game plays. Outliner > Add… > Controller sets one down in the middle of the view, already selected; the editor draws it as a small framed arrow and the game never draws it. The editor writes its name beside the mark, green while Enabled, grey while off. Its Properties:
- Enabled
- Off, it does nothing.
- Event
- The event it runs: the event's
[run]section, or with none its first section that holds a line. New at the end of the list makes one with its[run]section waiting; Edit File opens the picked one. - When
- Map start runs it when the map starts in play. Condition runs it when its condition is true. Timer runs it after Every seconds.
- Condition
- A reading, written as an
iftakes one:flag(gate_open),wolves >= 3,defeated(Wolf) >= 3,defeated(all) >= 3,px > 900 and py < 400(the player in an area),count(key) > 0. - Repeat
- Off, it runs once. On, it runs again every Every seconds (a Condition one only while its condition is true), Times times; Times 0 is no limit.
A controller waits its turn while another event is running. Every controller starts over when its map is read: a new game, a travel, a load. In a script, controller lists each controller with how many times it has run, controller <name> <key> <value> sets one (on, off, run, when, if, every, repeat, times), and object create controller <name> <x> <y> makes one.
Objects made by a script
object create puts a thing into the world while the game runs, with a name a later line can find it by; object destroy <name> takes it out, and object hide <name> and object show <name> switch a prop, barrier, wall, light or effect off and on where it stands, its collision with it.
[enter]
object create barrier gate 900 500 128 32
object create enemy Wolf boss at gate
object create light lamp at player 200[death]
object destroy gateThe kinds are prop <art> (a picture or model, or cube, sphere, cylinder, cone, plane, capsule, torus), barrier [wide deep tall] (a solid box, the project's cube stretched to that size; in a 2D project a wall), wall [wide deep] (the same with no picture), light [radius], effect <burst> [seconds], enemy <type>, npc <kind> and controller. The place is <x> <y>, or at and a name: player, death (where the last On death event's enemy fell), or anything named. Several things may share one name, and destroy, hide and show act on all of them; object destroy self takes out the prop whose event is running. A barrier blocks the player, enemies and their pathfinding from the moment it is made and stops the moment it is destroyed or hidden. What a script makes in play is not written into the map: the map reads again as it was made, and a saved game does not keep it, so make it again from a Map start controller.
The event gizmo
Right-click a villager and choose Events, or press Logic on a zone's row of the Zones page, to open a small panel beside it rather than a window. Chips across its top are its hooks, named by the section each writes ([enter] for zones, [talk] and [killed] for villagers); a chip is lit when it has lines behind it. Click a chip to see its steps: each row is one verb with its arguments, reordered with the arrows, removed with x, and added with + Add Step. Each row is one line of the event file, and the gizmo only rewrites its own section. Open as text opens the same file in the Text Editor.
A run step calls another event. Click its words for the list of the project's events: picking one writes run <event> <section> with the section that event runs first; New makes event_N with a [use] section and opens it; Edit File opens the event the step names; Section lets you type the words yourself.
One event calls another
run <event> [section] runs that section of another event, then the event that called it carries on with its next line. With no section named, [use] runs. Two in a row run one after the other:
[death]
run open_gate
run drop_rewardSo an enemy's On death, On spawn or On notice, a prop's use, a controller, a zone or a villager can share the work of several events. A run line in a quest's reward, a dialog action or a random event's verb starts its event when no script holds the stage, or as soon as the running one ends. A called event sees the same things as its caller: self is still the thing whose event started (the prop, the enemy of an On notice or On spawn), the place words death, notice and spawn and the holes {deathx}, {noticex}, {spawnx} and the rest still read the event that started it, and variables and flags are the game's own.
Calls nest at most 16 deep. A call to a section that is already running (an event calling itself, or two events calling each other in a ring) is not made: the line run selfie use: not run, selfie [use] is already running and would call itself without end goes to the Rûn Console and the Event Debugger's log, and the caller carries on. A call to an event with no file, or to a section it does not have, says so the same way: run gate_open: no event called "gate_open". The checker names both while you type: a missing event is an error, a missing section a warning.
The Events tools
The EVENTS pages of Edit > Project Settings list the map's Zones, the project's Event Files, and the Wiring between them: which zone, prop and villager calls which event. A hook whose script does not exist yet shows Create, which writes it and opens it; the rest show Open.
On the Files page, an event whose name appears nowhere in the project (not in another script, a data table, a map, a character or the project's settings, and not named like a map) is marked Unused. Under CALLED, NO FILE are the names something calls that have no file: a run line, an enemy type's On death, On spawn or On notice, or this map's zones, props, controllers and villagers. Each says who calls it, and Create writes it with the section that caller runs.
A zone's first script
- Open Edit > Project Settings... and choose Wiring under EVENTS.
- Find the zone's row, such as
zone_1, and press Create. - The Text Editor opens on the new script:
[enter]
say Something stirs...- Change the
sayline to your own words. Addflag set <name>on a line of its own to set a flag, and any other verbs the same way. For example,creditsrolls the credits. - Press Ctrl+S to save. Closing the Text Editor saves too.
Walk into the zone in play and the [enter] lines run.
A line in the chat box, with no villager
say shows its words at the bottom of the screen for a few seconds. speak opens the chat box instead: a speaker's name, the words, and a portrait if you name a picture. No villager is needed, so an object's [use] script or a random event can talk. The script waits until the box is closed, then runs its next line.
[use]
speak Old Sign : Keep out.
speak Old Sign portrait=assets/icons/sign.png : The mine is closed.
speak line in play: the speaker's name and the words, above the hotbar.In a random event, add an outcome of kind speak: what is the speaker, text is the words, and where is the portrait picture.
Random events
assets/data/randomevents.vfa, as rows; open it in the asset manager to edit them as tables. A trigger row says when the game asks (its kind: timer, travel, zone, daytime, weather, rest, story, load or called) and which tables it draws from. A table row is a weighted draw (nothing is the weight of drawing nothing) over its entry rows, and each entry names an event. An event's outcome rows say what happens, in order: say, gold, item, weather, spawn, setflag, quest and more, or script, which runs that script's [random] section.
comp trigger road_walk -1 -
field kind timer
field every 60 120
field unit seconds
field tables road_events
comp table road_events -1 -
field draw nottwice
field nothing 70
comp entry road_events.found_coins -1 -
field table road_events
field event found_coins
field weight 10
comp event found_coins -1 -
field label Found coins
comp outcome found_coins.1 -1 -
field event found_coins
field order 1
field kind gold
field amount 5 + level * 2A script that is already running is never interrupted; fate waits its turn, and waits out a conversation, a shop, a fight or a cutscene too. Every event that runs shows in the Event Debugger's log.
Flags
flag set <name> is how the world remembers. Quests advance on flags, require flag gates on them, and every villager's death sets killed_<name>. Flags ride the save.