Rûn Style Guide
A few conventions that make scripts easy to read for whoever opens them next, including yourself in a month. None of them is required by the engine.
Names
- Name files, events, flags and variables in lower case with underscores:
barn_door,met_the_king,wolves_left. - Name a flag for what became true:
gate_open,elder_thanked, notflag1. - Name program functions with a capital first letter, as the engine's own methods are:
Roll,RewardFor,IsNight. Name program variables in lower case. - Give a function's own variables names its callers do not use (see Rûn Variables and Scope).
- Prefix the files of one feature alike:
well_use,well_count,well_reward.
Layout
- Indent the lines under an event script
if,whileorrepeatby two spaces, and do not mix tabs and spaces in one block. - Indent program blocks by four spaces, and put
{at the end of the line that opens the block. - One statement per line. Use
;only to keep a very short pair together. - A blank line between sections and between functions.
- A comment on the first line of a file saying what the script is for.
// the wishing well: one coin, one wish, three wishes a game
RewardFor(number roll) {
if (roll >= 18) {
return "a ring"
}
if (roll >= 10) {
return "a coin back"
}
return "nothing"
}
for (number roll = 5; roll <= 20; roll = roll + 5) {
print(roll, RewardFor(roll))
}5 nothing
10 a coin back
15 a coin back
20 a ringChoosing the kind
- Write what the world does in event scripts: the words she sees, the items she gets, the flags that change.
- Write arithmetic and rules in programs, and call them from the event scripts.
- Keep numbers that must survive a save in event script variables or flags (see Rûn Saving State).
- Keep a scene with the camera and people moving at once in a block script.
Checking
- Run
check <event>at the console, or open the asset manager's Check panel, after every change. - Try a line at the console before putting it in a script.
- Print while you work out a program, and take the prints out when it works; the player never sees
print.