Line Scripts
A line script is a set of sections. Each section starts with its name in square brackets and holds one verb per line, run top to bottom.
# the barn door
[use]
require flag has_barn_key : locked
say The door creaks open.
solid barn_door off
swapimg barn_door BarnDoor_Open.png
flag set barn_opened
[locked]
say It will not budge.- A
#comment must be on a line of its own. After a verb it becomes part of what the verb says. - Indent lines with spaces to put them inside an
if,else,whileorrepeat. Two is usual. A tab counts as an indent: it reaches the next multiple of four columns. - Braces work as well as indents:
if (randovalue = 1) {,} else {or} else if (randovalue = 2) {, and}on a line of its own. A{may also stand alone on the line under itsif,else,whileorrepeat. The checker names a{that is never closed and a}that closes nothing. A wholeif (x) { ... }on one line is not read: put its body on the lines below. - Words in
{curly braces}fill in live values:say You carry {gold} coins.orsay {currency(tokens)} tokens left.{rung <party>}fills in the name of the rung the player stands on with that party, or her standing when it has no ladder (Factions and Reputation). In a zone's script,{zonewho},{zonekind}and{zonename}name who walked in and where. - A
sayline stays on screen for a while. When another comes while it is still up, the first stands above the new one until its own time ends, so both are read: a pickup's Picked up line and its event's ownsay, for one. - A section runs at most 64 lines. Past that, lines are not run, so split a long scene into sections and
runthem. The checker marks the first line past the 64th as an error.
Flow
- set <var> <expr>
- Make or change a variable. Words that are not arithmetic become text; "words in quotes" are text; another variable's name copies its value.
<var> = <expr>on a line does the same. See Variables and Counters. - add <var> <expr>
- Add to a number (a negative amount subtracts).
- if <condition>
- The indented lines below run when it is true.
- else
- The other way, at the same indent as its
if. - while <condition>
- The indented lines repeat while it is true. A loop that runs away is caught and paused.
- repeat <count>
- The indented lines run that many times.
- require flag <name> : <section>
- Carry on only if the flag is set; otherwise jump to the section.
- require <stat> <dc> : <section>
- A hidden d20 roll plus the attribute's modifier against the number; falling short jumps to the section.
- wait <seconds>
- Pause this script. Seconds, not milliseconds:
wait 0.5is half a second. - run <name> [section]
- Run another script (its
[use]when no section is named); this one carries on after it. Scripts can run one inside another four deep. - end
- Stop this section here.
- every <seconds>
- The whole section re-runs on that heartbeat for as long as the map is loaded. Arm it from a map's
[load]. The shortest beat is 0.25 seconds, and waits inside it are skipped.
Variables are shared: every line script sees them. A save keeps them and a load puts them back; a new game, and each new test in the editor, starts with none. See Variables and Counters.
Conditions
Numbers, variables, + - * /, comparisons (= != < > <= >=), and, or, not and brackets, plus readings of the world:
hp maxhp mp maxmp gold level xp points fame px py hour day night
count(<item>) flag(<name>) rand(<n>) curve(<name>, <step>) dist(<who>)
stat(<attr>) knows(<spell>) learned(<skill>) equipped(<item>) currency(<id>)
quest(<id>) questdone(<id>) alive(<type>) defeated(<type>) onmap(<map>) cooldown(<timer>)
standing(<party>) esteem(<party>) grievance(<party>) member(<party>) rank(<party>) rung(<party>)
open(<prop>) broken(<prop>) visible(<prop>) stepup(<prop>) tweening(<prop>) self(<prop>, <A-D>) prop(<prop>, <key>)
held(<action>) pressed(<action>) setting(<key>) noteread(<item>) notefound(<item>)
price(<item>) supply(<item>) route(<id>) inregion(<region>)
happened(<event>) since(<event>) pacing resting zoneher zoneindexA few of them:
nightis 1 between sunset and sunrise.alive(goblin_1)counts living enemies of a type;alive(all)counts them all.defeated(<type>)is how many of a type the player has defeated, the number the {bestiary} shows.dist(<who>)is the distance to a villager or a tagged prop.open,broken,visibleandtweeningask about a prop: a door standing open, a breakable that broke, a prop that is shown, a prop that is moving.held(<action>)is 1 while an action's key is down,pressed(<action>)only on the frame it went down. Custom actions count (Controls and Gamepad).priceandsupplyread an item's price and supply where she stands, orprice(<region>, <item>)in a region.routeis 1 while a trade route is open (Maps and Travel).happened(<event>)is how many times a random event has run, andsince(<event>)the game hours since it last did (Events and Triggers).
The party readings are the factions' view of the player. member is 0 or 1, rank 0 when she is not a member, and rung the place of her rung on that party's ladder (1 = the lowest, 0 = no ladder). After rung(<party>) and a comparison, a rung's name stands for its place: if rung(marsh) >= Liked. <party> may be speaker, the party of the villager she is talking to.
Example: if gold >= 50 and dist(elder_runa) < 200
The verbs
Every verb, grouped by what it does, with its signature and an example, is on the Rûn Verb Index page. The most used:
- say, dialog, deed, shop
- Speech, conversations, the journal, shops.
- flag, quest
- Story flags and quest stages.
- travel, teleport, move, face, anim
- Moving people.
- spawn, recruit, dismiss, learnspell
- Enemies, companions, spells.
- swapimg, solid, prop, fx, sprite, weather, time, music, sound
- The world.
- lock, unlock, fade, letterbox, title, cinetext, camera, shake, flash, video
- Scenes. See Cutscenes.
Build your own verbs
A script is a verb made of verbs. Write bolt once:
[use]
sprite assets/fx/scorch.png player 3 1.2
fx hit_storm player
sound thunder.wav
shake 0.7 16and run bolt anywhere throws lightning. (scorch.png and thunder.wav are your own files; hit_storm is one of the effects the engine ships.)