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 |
table("Item", "Sword", "damage") | A cell of a data table: the table, the row name, the column |
t("menu.play") | A text from Files → Localization in the current language; {0}, {1} in it are filled by extra arguments: t("score", points) |
tablerow("Item", index) | The name of a row of a data table by number (0 is the first), to go through every row with a loop |
achievementcount() | How many achievements Files → Services has (to go through them with a loop) |
achievementid(index) | The id of an achievement by number (0 is the first) |
achievementname(index or id) | The name of an achievement, by number or id |
achievementsteps(id) | Steps done of an achievement (all of them once unlocked) |
achievementgoal(id) | Steps an achievement needs (1 for a plain one) |
achievementdone(id) | 1 when the achievement is unlocked, else 0 |
bestscore(id) | The best score sent to a leaderboard from this device (0 when none) |
productprice(id) | The price text of a product, e.g. "$1.99" |
scenename() | The name of the running scene |
tablecount("Item") | How many rows a data table has |
time | Seconds since the scene started |
dt | Seconds since the last frame (multiply speeds by dt) |
fps | Frames per second |
loadingProgress | On a loading screen: how far it got, 0 to 1 (for a loading bar). It is 1 exactly when the game is ready to leave the screen |
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) |
hypot(a, b, ...) | Length of a vector: sqrt(a² + b² + …), e.g. hypot(vx, vz) is the speed |
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 |
Multiplayer
| Function | What it does |
|---|---|
netcode() | The code of the room you are in (give it to friends so they can join); empty when not in a room |
netishost() | 1 when you are the host of the room (the player who has been in it the longest), else 0 |
netonline() | 1 when you are in a room, else 0 |
netplayers() | How many players are in the room, you included |
netplayername(index) | The name of a player by number (0 is the first to have joined); use with a loop |
netplayerid(index) | The id of a player by number (0 is the first to have joined) |
netmyname() | Your name in the room |
netmyid() | Your id in the room (0 when not in one) |
netping() | The round trip to the room in milliseconds (a reading every few seconds); 0 when not in a room or before the first one |
nethostname() | The name of the host |
netwho() | In "On player joined", "On player left" and "On message": the name of that player |
netwhoid() | In "On player joined", "On player left" and "On message": the id of that player |
netmessage() | The name of the latest message received |
netdata("x") | In "On message": what the message carries. Without a name it is the whole value; with one it is that part of an object ("x" or "pos.z") |
netshared("name") | A value the whole room shares (set with Set shared value); empty when it is not set. A late joiner gets them at once |
neterror() | In "On room failed": why (notfound, full, busy or offline) |
Web
| Function | What it does |
|---|---|
webstatus() | In "On web response" / "On web error": the status code of the reply (200, 404…; 0 when no reply came) |
webok() | 1 when the latest web request got a 2xx reply, else 0 |
webtext() | The reply of the latest web request as text |
webjson("scores.0.name") | A value inside the JSON reply of the latest web request: dots go into objects, numbers pick from lists. Empty when it is not there |
webjsoncount("scores") | How many items the list (or keys the object) at that place in the JSON reply has |
weberror() | In "On web error": what went wrong, in words |
webname() | The name given to the request that the latest reply answers |
Audio
| Function | What it does |
|---|---|
musicbeat() | Beats since the music started (0, 1, 2 …; 4 to a bar), -1 when no music with a tempo plays |
musicbar() | Bars since the music started, -1 when none. musicbeat() % 4 is the beat in the bar (0-3) |
musictime() | Seconds into the music playing (0 when none) |
musicbpm() | The music's tempo in beats a minute (0 when unknown) |
Steam
| Function | What it does |
|---|---|
steamname() | The player's Steam name (empty without Steam) |
steamlanguage() | The language picked for the game in Steam ("english", "french" …; empty without Steam) |
Input
| Function | What it does |
|---|---|
prompt(control, device?) | The key or gamepad button of a control button on the device in use: "Space", "A"; "move" gives WASD. In UI text, <prompt=jump> draws it as a key cap or a gamepad button |
padstyle() | Whose button names gamepad prompts show: "xbox", "playstation", "switch" or "deck" (from the gamepad in use, or Set gamepad prompt style) |
inputdevice() | What the player used last: "gamepad", "keyboard" (keys or mouse) or "touch" |
touchX | Finger X position on screen |
touchY | Finger Y position on screen |
touchWorldX | X of the spot in the world under the finger / mouse (the ground or an object) |
touchWorldY | Y (height) of the spot in the world under the finger / mouse |
touchWorldZ | Z of the spot in the world under the finger / mouse |
joystickX | Joystick left/right (-1 to 1) |
joystickY | Joystick down/up (-1 to 1) |
lookX | Mouse / right stick / drag turn this frame, in degrees (right = positive) |
lookY | Mouse / right stick / drag tilt this frame, in degrees (up = positive) |
Raycast
| Function | What it does |
|---|---|
rayhitname() | After a "Raycast" condition: the name of the object the ray hit (empty when nothing) |
rayHitX | After a "Raycast" condition: X of the point the ray hit |
rayHitY | After a "Raycast" condition: Y (height) of the point the ray hit |
rayHitZ | After a "Raycast" condition: Z of the point the ray hit |
rayNormalX | After a "Raycast" condition: X of the direction the hit surface faces |
rayNormalY | After a "Raycast" condition: Y of the direction the hit surface faces (1 = flat ground) |
rayNormalZ | After a "Raycast" condition: Z of the direction the hit surface faces |
rayDistance | After a "Raycast" condition: how far the ray travelled before it hit (meters) |
Collision
| Function | What it does |
|---|---|
hitX | In "On collision with" or "Is touching": X of the point where they touched |
hitY | In "On collision with" or "Is touching": Y (height) of the point where they touched |
hitZ | In "On collision with" or "Is touching": Z of the point where they touched |
hitNormalX | In "On collision with" or "Is touching": X of the surface direction at the hit, pointing out of the other object toward this one |
hitNormalY | In "On collision with" or "Is touching": Y of the surface direction at the hit (1 = landed on top of the other object, -1 = hit it from below) |
hitNormalZ | In "On collision with" or "Is touching": Z of the surface direction at the hit |
hitSpeed | In "On collision with" or "Is touching": how fast they hit each other (m/s), e.g. damage or a sound volume |
hitImpulse | In "On collision with" or "Is touching": how hard the physics pushed them apart (N·s); 0 for triggers (hitX/Y/Z and the surface direction are only estimated there) |
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 (a UI element: its offset from its anchors, what Set position sets) |
.y | Y position, the height (a UI element: its offset from its anchors, Y up) |
.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) |
.jointAngle | Hinge Joint: angle in degrees from where it started (slider: metres moved) |
.jointSpeed | Hinge or wheel Joint: turning speed in degrees per second (slider: metres per second) |
.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 |
.hipsX | X of the hips of a ragdoll (the object stays put); its own position when not limp |
.hipsY | Y of the hips of a ragdoll |
.hipsZ | Z of the hips of a ragdoll |
.ownerName | Multiplayer: the name of the player who drives this object (empty when nobody does, or it is not synced) |
.ownerId | Multiplayer: the id of the player who drives this object (0 when nobody does) |
.text | Text shown (text objects) |
.visible | true if visible |
.name | Object name |
.id | Unique id of the instance |
.value | Slider / bar value (UI) |
.width | Width of a UI element (what Set size sets) |
.height | Height of a UI element (what Set size sets) |
.centerX | UI element: where the MIDDLE of its box is drawn, in canvas px from the left. Use it to put something on top of this element |
.centerY | UI element: where the MIDDLE of its box is drawn, in canvas px from the bottom |
.screenX | UI element: where its PIVOT is drawn, in canvas px from the left, whatever its parent. Use it to place something relative to this element (screenX + 40) |
.screenY | UI element: where its PIVOT is drawn, in canvas px from the bottom |
.min | Slider / bar minimum (UI) |
.max | Slider / 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 · lookX · lookY · touchWorldX · touchWorldY · touchWorldZ · loopIndex · timeScale · loadingProgress · hitX · hitY · hitZ · hitNormalX · hitNormalY · hitNormalZ · hitSpeed · hitImpulse · rayHitX · rayHitY · rayHitZ · rayNormalX · rayNormalY · rayNormalZ · rayDistance
Compare operators
Conditions such as Compare variable use: = ≠ < ≤ > ≥