Skip to content

Expressions and operators

Compiles

An expression is anything that produces a value: 3, speed * 2.0, $entity.get(), score > 10 && alive.

Operator Meaning Example
+ add (also joins strings) score + 1, "Hi " + name
- subtract, or negate max - used, -speed
* multiply speed * 2.0
/ divide distance / time
% remainder frame % 2
let per_team: int = 8
let players: int = 13
let teams: int = players / per_team + 1
let odd: bool = players % 2 == 1

== equal, != not equal, < less, <= less or equal, > greater, >= greater or equal. Each gives a bool. Strings compare with == too:

let name: string = "garage"
let is_garage: bool = name == "garage"
Operator Meaning
&& and: true when both sides are
|| or: true when either side is
! not: flips true and false
let alive: bool = true
let holding_ball: bool = false
let can_catch: bool = alive && !holding_ball

From first worked out to last, in the same order as school maths, then logic:

Order Operators
1 . member access, as casts, calls
2 ! - (unary)
3 * / %
4 + -
5 == != < <= > >=
6 &&
7 ||

When in doubt, add parentheses. (a + b) * c is always clearer than relying on the table.

as converts a value to another type. It’s how you turn an int into a float and back, or tell the compiler what a var holds:

let whole: int = 7
let half: float = (whole as float) / 2.0

A dot reads a part of a value: a vector’s x, y, z, w, or a field of another component (see Talking to other scripts):

let spot: vec3 = vec3(10, 20, 30)
let height: float = spot.z

if can pick between two values. Both branches are required:

let score: int = 12
let label: string = if score > 10 { "high" } else { "low" }
For programmers

Precedence is || < && < comparisons < additive < multiplicative < unary < postfix. Comparisons are left-associative and don’t chain meaningfully (a < b < c compares a bool), same as C. if cond { a } else { b } is the ternary; each branch is a single expression.