Skip to content

Operators

From tightest to loosest:

Level Operators Grouping
1 postfix . [] () ++ -- left
2 unary - !, prefix ++ --, await right
3 & | (one shared level) left
4 ^ left
5 * / % left
6 + - left
7 << >> left
8 @ SPC NL TAB left
9 in left
10 == != === !== < > <= >= left
11 && left
12 || left
13 ?: right
14 = and the compound assignments right

Three places differ from C. & and | bind tighter than comparisons and share one level, so 5 & 3 == 1 is 1. in binds tighter than the comparisons, so 1 == 2 in {0} is 1 == (2 in {0}), which is 0. ^ is power and groups to the left: 2 ^ 3 ^ 2 is 64, and -2 ^ 2 is 4. When in doubt, add parentheses.

function onCreated() {
echo(2 ^ 3 ^ 2);
// expect: 64
echo(-2 ^ 2);
// expect: 4
echo(5 & 3 == 1);
// expect: 1
echo(1 + 2 << 3);
// expect: 24
}

Run this example in the playground

+ - * / turn both sides into numbers and compute in 64-bit floating point.

  • Every result is limited to [-2147483647, 2147483647]. 2 ^ 40 and 3000000000 / 1 give 2147483647. The operands themselves are not limited: 3000000000 > 2147483647 is true.
  • Dividing by zero, or % by zero, gives 0 and reports nothing.
  • % takes the sign of the right side: -7 % 3 is 2 and 7 % -3 is -2. It works on decimals.
  • ^ with a base of 0, or with an invalid domain such as (-8) ^ (1 / 3), gives 0.
function onCreated() {
echo(7 / 2);
// expect: 3.5
echo(-7 % 3);
// expect: 2
echo(7 / 0);
// expect: 0
echo(2 ^ 40);
// expect: 2147483647
}

Run this example in the playground

& | << >> work on unsigned 32-bit integers. A negative number becomes floor(x) + 1 first, so -1 & 255 is 0 and -3 & 255 is 254. Shift counts use their low 5 bits: 1 << 32 is 1. The same rules apply to constants and to variables.

function onCreated() {
echo(5.7 & 3);
// expect: 1
echo(1 << 4);
// expect: 16
echo(-3 & 255);
// expect: 254
}

Run this example in the playground

a xor b is the bitwise exclusive or of the same unsigned operands, so 5 xor 3 is 6. ~a is the signed complement of the operand, so ~5 is -6 and ~0 is -1. xor is an operator only between two operands; elsewhere it is an ordinary name.

function onCreated() {
echo(5 xor 3);
// expect: 6
echo(~5);
// expect: -6
}

Run this example in the playground

== and != (loose equality):

  • Two strings, or a string and an empty value, are equal when they match ignoring case: "abc" == "ABC", but "10" == "10.0" is false.
  • A number and a string meet as numbers, within 0.0001: 1 == "1", 0.1 + 0.2 == 0.3, and "1e2" == 100 are true.
  • Arrays are equal only when they are the very same array. Contents are never compared.
  • Objects are equal only when they are the same object.

=== and !== (strict equality, an engine extension) need the same kind and origin tag: 1 === "1" is false, {1, 2} === {1, 2} is true, and strings are compared byte for byte.

< > <= >= turn both sides into numbers and compare within 0.0001. Two non-numeric strings are both -1, so "abc" < "abd" is false. Compare text with a helper, not with <.

function onCreated() {
echo(1 == "1");
// expect: 1
echo("abc" == "ABC");
// expect: 1
echo("10" == "10.0");
// expect: 0
echo(1 === "1");
// expect: 0
echo({1, 2} === {1, 2});
// expect: 1
echo("5" < "10");
// expect: 1
}

Run this example in the playground

a @ b joins two texts. a SPC b joins with one space, a NL b with a new line, and a TAB b with a tab. a @= b means a = a @ b.

function onCreated() {
echo("x" SPC "y" @ "z");
// expect: x yz
temp.s = "ab";
temp.s @= "cd";
echo(temp.s);
// expect: abcd
}

Run this example in the playground

!a, a && b, and a || b give 1 or 0. && and || skip the right side when the left side decides the answer (OQ-LANG-20).

0, 0.0, "", "0", an empty value, an empty array, and a non-empty array are false. A string is false when its number value is 0: "0.0", " 0", "-0", "0a". Every other string is true, including "abc". Objects and functions are false as well, because their number value is 0: test an object with obj != null, not with if (obj).

Because a non-empty array is false, write if (temp.list != NULL) and not if (temp.list). The compiler warns about the second form (W-ARRAY-TRUTHINESS).

function onCreated() {
echo("abc" ? "true" : "false");
// expect: true
echo("0.0" ? "true" : "false");
// expect: false
echo({1, 2} ? "true" : "false");
// expect: false
}

Run this example in the playground

value in list is true when the array, or a list string, has an element loosely equal to the value. value in |min, max| tests min <= value <= max. Inside the bars, a bitwise | needs parentheses.

function onCreated() {
echo(2 in {1, 2, 3});
// expect: 1
echo(5.5 in |1, 5|);
// expect: 0
echo("2" in "1,2,3");
// expect: 1
}

Run this example in the playground

c ? a : b evaluates only the branch it picks. x ? y : !z works without extra parentheses (older scripts needed them; the compiler can warn with W-TERNARY-NOT).

x++, ++x, x--, --x work on any variable. An empty variable becomes 1 (or -1). A non-numeric text becomes 0. The postfix form gives the old value, the prefix form the new one.

(@ expression) followed by (arguments) calls a function by name or by function value: (@ "myFunc")(3). Without arguments it looks up a script object (a database NPC or a weapon) by name, or gives empty when none exists.

a op= b is a = a op b, and the place on the left is worked out once. The forms are += -= *= /= %= @= &= |= <<= >>=.

:= is another spelling of =: temp.a := 5; works as temp.a = 5;. It exists for scripts written for the legacy server.

Engine version 0.1.0. Built 2026-11-18.