Skip to content

Operators

OperatorDescriptionExample
+Addition / string concatenation5 + 38
-Subtraction10 - 46
*Multiplication / string repeat3 * 412
/Division10 / 33
%Modulo10 % 31
**Power / exponentiation2 ** 101024

Integer division truncates. If either operand is a Potion (float), the result is a Potion:

Chant(10 / 3); // 3 (integer division)
Chant(10.0 / 3); // 3.3333... (float division)

The + operator concatenates any value with a string:

Chant("Level " + 5); // "Level 5"
Chant("HP: " + 3.14); // "HP: 3.14"
Chant("Alive: " + Truth); // "Alive: Truth"

The * operator repeats a string:

Chant("ha" * 3); // "hahaha"
Chant("-" * 20); // "--------------------"
OperatorDescriptionExample
matches or ==Equalityx matches 5
!=Not equalx != 0
<Less thanx < 10
>Greater thanx > 0
<=Less than or equalx <= 100
>=Greater than or equalx >= 1

RuneLang has no implicit type coercion. Comparing a Countstone to a Runestone is a type error, not a silent false.

The matches keyword is the idiomatic way to check equality. == is supported as an alias for developers coming from other languages.

OperatorDescriptionExample
andLogical ANDx > 0 and x < 100
orLogical ORx matches 0 or x matches 1
notLogical NOTnot is_dead

Logical operators short-circuit: and stops at the first falsy value, or stops at the first truthy value.

OperatorDescriptionExample
&Bitwise AND0b1100 & 0b10108
|Bitwise OR0b1100 | 0b101014
^Bitwise XOR0b1100 ^ 0b10106
~Bitwise NOT~0-1
<<Left shift1 << 416
>>Right shift16 >> 24

Bitwise operators only work on Countstone (integer) values.

The in operator tests whether a value exists in a collection:

Scroll heroes is ["Gandalf", "Frodo", "Aragorn"];
Chant("Frodo" in heroes); // Truth
Chant("Sauron" in heroes); // Falsehood
// works on strings
Chant("ello" in "hello"); // Truth
// works on tomes (checks keys)
Tome stats is {"str": 18, "dex": 14};
Chant("str" in stats); // Truth

From lowest to highest precedence:

LevelOperatorsAssociativity
1orLeft
2andLeft
3|Left
4^Left
5&Left
6matches == !=Left
7< > <= >= inLeft
8<< >>Left
9+ -Left
10* / %Left
11**Right
12- (unary) not ~Right

Use parentheses to override precedence when needed:

Countstone result is (1 + 2) * 3; // 9, not 7