Expressions and operators
CompilesAn expression is anything that produces a value: 3, speed * 2.0, $entity.get(), score > 10 && alive.
Arithmetic
Section titled “Arithmetic”| 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 = 8let players: int = 13let teams: int = players / per_team + 1let odd: bool = players % 2 == 1Comparison
Section titled “Comparison”== 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 = truelet holding_ball: bool = falselet can_catch: bool = alive && !holding_ballOrder of operations
Section titled “Order of operations”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 = 7let half: float = (whole as float) / 2.0Member access
Section titled “Member access”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.zChoosing a value with if
Section titled “Choosing a value with if”if can pick between two values. Both branches are required:
let score: int = 12let 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.