Rûn Expressions and Operators
An expression is anything that has a value: 3, hp, gold >= 50, round(random(0, 50)). Event scripts and programs each have their own expression language. They look alike and differ in a few places that matter.
In programs
From the tightest to the loosest. Operators on one row are applied left to right.
-x,!x- Negative; not (true when x is false).
*,/,%- Times, divided by, remainder.
+,-- Plus (joins text when either side is text), minus.
<,>,<=,>=- Comparisons of numbers.
==,!=- Equal and not equal, for numbers, text, toggles and declared names.
&&- And. The right side is not worked out when the left is false.
||- Or. The right side is not worked out when the left is true.
number a = -2
print(-a, !true, 2 + 3 * 4, (2 + 3) * 4, 10 - 2 - 3)
print(1 + 1 == 2 && 3 > 2 || false)2 off 14 20 5
on= sets a variable and is not an operator: it cannot stand inside an if. The words and, or and not are refused in programs with the symbol to use instead.
number hp = 5
if (hp > 0 and hp < 10) print("hurt")a program writes and as && -> && for and, || for or, ! for notDividing by zero and taking % of zero stop the program with an error. % keeps the sign of the left side; mod(x, y) never goes below 0 for a y above 0, which is what a wrap-around counter wants.
print(-7 % 3, mod(-7, 3), 7.5 % 2)-1 2 1.5In event scripts
The conditions of if, while and require, and the values of set and add, use this language. From the tightest to the loosest:
-x,not x- Negative; not.
nottakes only the value right after it. *,/- Times, divided by. Dividing by zero gives 0.
+,-- Plus, minus. Numbers only.
=or==,!=,<,>,<=,>=- Comparisons. One per side of an
andoror;=and==mean the same. and,or- Both on one level, applied left to right.
and does not bind tighter than or in an event script: if a or b and c means if (a or b) and c. Use brackets: if a or (b and c).
There is no % in an event script. A set whose value does not read as arithmetic keeps it as text, so set m 7 % 2 makes m the text 7 % 2.
Words in a condition are readings of the world (hp, gold, night, count(<item>), flag(<name>), rand(<n>) and the rest listed on Line Scripts) or variables. A name that is neither reads as 0. The number in rand(<n>) may be a variable or a sum: rand(lim), rand(lim + 1).
[use]
set roll rand(51)
if roll < 10
set verdict 1
else
set verdict 2
if gold >= 0 and roll <= 50
add checks 1The built-in functions of programs
These are called by name in any program and at the console. A function of your own with the same name as a math function is used instead of it.
- random(max), random(min, max)
- A fraction from min (0 when left out) up to, never reaching, max.
- rand(n), rand(min, max)
- A whole number: rand(n) is 0 to n-1, rand(min, max) is min to max with both ends included.
- pick(a, b, ...)
- One of its arguments, at random.
- round(x), round(x, places)
- x to the nearest whole number, or to that many places.
- floor(x), ceil(x), int(x)
- Down, up, and toward 0 to a whole number.
- abs(x), sign(x)
- x without its sign; -1, 0 or 1.
- min(a, b, ...), max(a, b, ...)
- The smallest and largest of two to eight numbers.
- clamp(x, low, high)
- x held between low and high.
- sqrt(x), pow(x, y)
- The square root (an error below 0); x to the power y.
- mod(x, y)
- The remainder of x over y, never below 0 for a y above 0.
- lerp(a, b, t)
- The point t of the way from a to b.
- print(...)
- Writes up to eight arguments to the console, one space between.
- refuse("why")
- In a
beforeblock: the event does not happen (see Rûn Rule Blocks). - roll("1d20+3")
- Dice through the d20 rules; the total.
The d20 fight's own functions (ap(), endturn(), hitchance(), conditions() ...) are listed under Built in on Rûn Programs.
print(round(2.5), round(3.14159, 2), floor(-3.5), ceil(3.2), int(-3.7))
print(abs(-5), sign(-0.5), min(4, 2, 9), max(4, 2, 9), clamp(150, 0, 100))
print(sqrt(16), pow(2, 8), lerp(0, 100, 0.25))3 3.14 -4 4 -3
5 -1 2 9 100
4 256 25Random whole numbers
random(0, 50) gives fractions such as 37.21. For a whole number, take floor of one more than the largest you want: floor(random(0, 51)) gives 0 to 50, each as likely as the others. round(random(0, 50)) also gives 0 to 50, but 0 and 50 come up half as often as the numbers between. Both names work, in programs and in event scripts alike, and they differ on purpose: random gives ANY number in the range (round or floor it for a whole one), rand gives a WHOLE number. rand(51) is 0 to 50, and rand(1, 6) is 1 to 6 with both ends included, like a die. Inside either, a variable or a sum may stand for a number: rand(1, lim). Event scripts also read round, floor, ceil, int, abs, sqrt, min, max and clamp, so set r round(random(1, 2)) gives 1 or 2.
number lowest = 100
number highest = -1
for (number i = 0; i < 2000; i = i + 1) {
number d = floor(random(1, 7))
lowest = min(lowest, d)
highest = max(highest, d)
}
print("a six-sided die gave", lowest, "to", highest)a six-sided die gave 1 to 6