Expressions
Every number or text field in an event is an expression: a small formula the game works out while it runs. Type 10, Score + 1, "Score: " + Score, Player.x or random(1, 6).
Values and operators
| Write | Meaning |
|---|---|
12, 3.5, -1 | Numbers |
"text" or 'text' | Text (with quotes) |
true, false | Yes / no |
+ - * / % , ^, mod | Math. + joins text when either side is text: "Lives: " + Lives |
= <> != ≠ < <= ≤ > >= ≥ | Compare (gives true/false) |
and or not (also & | !) | Logic |
cond ? a : b | Pick a or b |
Score | A global, scene or local variable, by name |
Player.x | A property of an object (see below) |
Enemy.hp | An instance variable (also Enemy.var("hp")) |
If you mistype a name, the game keeps running: it shows a friendly message once and the unknown value counts as 0. The event with the problem gets a red badge in the editor.
Functions
Random
| Function | What it does |
|---|---|
random(min, max) | Random decimal number between min and max |
randomInt(min, max) | Random whole number from min to max (inclusive) |
choose(a, b, ...) | Picks one of the values at random |
Game
| Function | What it does |
|---|---|
loopindex("i") | Current number of the loop called "i" (For loop), or of the innermost loop without a name |
time | Seconds since the scene started |
dt | Seconds since the last frame (multiply speeds by dt) |
fps | Frames per second |
loopIndex | Current number of the innermost loop (Repeat, For, For each, While) |
screenWidth | Screen width in pixels |
screenHeight | Screen height in pixels |
Math
| Function | What it does |
|---|---|
abs(x) | Absolute value (removes the minus sign) |
min(a, b, ...) | Smallest value |
max(a, b, ...) | Largest value |
floor(x) | Round down |
ceil(x) | Round up |
round(x, digits?) | Round to nearest (optionally to N decimals) |
sqrt(x) | Square root |
pow(x, y) | x to the power of y (same as x ^ y) |
sign(x) | -1, 0 or 1 |
sin(degrees) | Sine (angle in degrees) |
cos(degrees) | Cosine (angle in degrees) |
tan(degrees) | Tangent (angle in degrees) |
atan2(y, x) | Angle in degrees of the vector (x, y) |
angle(x1, z1, x2, z2) | Angle (degrees, around Y) from point 1 to point 2 |
lerp(a, b, t) | Blend from a to b (t from 0 to 1) |
clamp(x, min, max) | Keep x between min and max |
distance(x1, z1, x2, z2) | Distance on the ground (X/Z) between two points |
distance3(x1, y1, z1, x2, y2, z2) | 3D distance between two points |
Convert
| Function | What it does |
|---|---|
int(x) | Whole number part (drops decimals) |
float(x) | Convert text to a number |
str(x) | Convert a number to text |
Text
| Function | What it does |
|---|---|
len(text) | Number of characters in a text |
upper(text) | UPPERCASE text |
lower(text) | lowercase text |
left(text, count) | First characters of a text |
right(text, count) | Last characters of a text |
mid(text, start, count) | Part of a text |
contains(text, part) | true if text contains part |
replace(text, find, with) | Replace every occurrence |
pad(value, length, char?) | Pad with leading zeros, e.g. 007 |
Input
| Function | What it does |
|---|---|
touchX | Finger X position on screen |
touchY | Finger Y position on screen |
joystickX | Joystick left/right (-1 to 1) |
joystickY | Joystick down/up (-1 to 1) |
Object properties
Write the object’s name (or Self inside an action on that object), a dot, then the property: Player.x, Coin.count, Self.angle.
| Property | What it gives |
|---|---|
.x | X position |
.y | Y position (height) |
.z | Z position |
.angle | Turn angle around Y (degrees) |
.rotX | Rotation X (degrees) |
.rotY | Rotation Y (degrees) |
.rotZ | Rotation Z (degrees) |
.scaleX | Scale X |
.scaleY | Scale Y |
.scaleZ | Scale Z |
.vx | Velocity X |
.vy | Velocity Y |
.vz | Velocity Z |
.speed | Speed (length of velocity) |
.count | Number of these objects in the scene |
.pickedCount | Number of picked instances in this event |
.worldX | World X position |
.worldY | World Y position |
.worldZ | World Z position |
.text | Text shown (text objects) |
.visible | true if visible |
.name | Object name |
.id | Unique id of the instance |
.value | Progress bar value (UI) |
.max | Progress bar maximum (UI) |
.pressed | UI button is held down |
Inside an action on an object type, Coin.x means the coin being processed. With several picked coins, the action runs once per coin and each sees its own values.
Built-in values
time · dt · fps · screenWidth · screenHeight · touchX · touchY · touching · joystickX · joystickY · loopIndex · timeScale
Compare operators
Conditions such as Compare variable use: = ≠ < ≤ > ≥