Skip to main content

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​

WriteMeaning
12, 3.5, -1Numbers
"text" or 'text'Text (with quotes)
true, falseYes / no
+ - * / % , ^, modMath. + joins text when either side is text: "Lives: " + Lives
= <> != ≠ < <= ≤ > >= ≥Compare (gives true/false)
and or not (also & | !)Logic
cond ? a : bPick a or b
ScoreA global, scene or local variable, by name
Player.xA property of an object (see below)
Enemy.hpAn instance variable (also Enemy.var("hp"))
Mistakes don’t crash the game

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​

FunctionWhat 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​

FunctionWhat 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
timeSeconds since the scene started
dtSeconds since the last frame (multiply speeds by dt)
fpsFrames per second
loadingProgressOn 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
loopIndexCurrent number of the innermost loop (Repeat, For, For each, While)
screenWidthScreen width in pixels
screenHeightScreen height in pixels

Math​

FunctionWhat 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​

FunctionWhat it does
int(x)Whole number part (drops decimals)
float(x)Convert text to a number
str(x)Convert a number to text

Text​

FunctionWhat 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​

FunctionWhat 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​

FunctionWhat 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​

FunctionWhat 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​

FunctionWhat 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​

FunctionWhat 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"
touchXFinger X position on screen
touchYFinger Y position on screen
touchWorldXX of the spot in the world under the finger / mouse (the ground or an object)
touchWorldYY (height) of the spot in the world under the finger / mouse
touchWorldZZ of the spot in the world under the finger / mouse
joystickXJoystick left/right (-1 to 1)
joystickYJoystick down/up (-1 to 1)
lookXMouse / right stick / drag turn this frame, in degrees (right = positive)
lookYMouse / right stick / drag tilt this frame, in degrees (up = positive)

Raycast​

FunctionWhat it does
rayhitname()After a "Raycast" condition: the name of the object the ray hit (empty when nothing)
rayHitXAfter a "Raycast" condition: X of the point the ray hit
rayHitYAfter a "Raycast" condition: Y (height) of the point the ray hit
rayHitZAfter a "Raycast" condition: Z of the point the ray hit
rayNormalXAfter a "Raycast" condition: X of the direction the hit surface faces
rayNormalYAfter a "Raycast" condition: Y of the direction the hit surface faces (1 = flat ground)
rayNormalZAfter a "Raycast" condition: Z of the direction the hit surface faces
rayDistanceAfter a "Raycast" condition: how far the ray travelled before it hit (meters)

Collision​

FunctionWhat it does
hitXIn "On collision with" or "Is touching": X of the point where they touched
hitYIn "On collision with" or "Is touching": Y (height) of the point where they touched
hitZIn "On collision with" or "Is touching": Z of the point where they touched
hitNormalXIn "On collision with" or "Is touching": X of the surface direction at the hit, pointing out of the other object toward this one
hitNormalYIn "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)
hitNormalZIn "On collision with" or "Is touching": Z of the surface direction at the hit
hitSpeedIn "On collision with" or "Is touching": how fast they hit each other (m/s), e.g. damage or a sound volume
hitImpulseIn "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.

PropertyWhat it gives
.xX position (a UI element: its offset from its anchors, what Set position sets)
.yY position, the height (a UI element: its offset from its anchors, Y up)
.zZ position
.angleTurn angle around Y (degrees)
.rotXRotation X (degrees)
.rotYRotation Y (degrees)
.rotZRotation Z (degrees)
.scaleXScale X
.scaleYScale Y
.scaleZScale Z
.vxVelocity X
.vyVelocity Y
.vzVelocity Z
.speedSpeed (length of velocity)
.jointAngleHinge Joint: angle in degrees from where it started (slider: metres moved)
.jointSpeedHinge or wheel Joint: turning speed in degrees per second (slider: metres per second)
.countNumber of these objects in the scene
.pickedCountNumber of picked instances in this event
.worldXWorld X position
.worldYWorld Y position
.worldZWorld Z position
.hipsXX of the hips of a ragdoll (the object stays put); its own position when not limp
.hipsYY of the hips of a ragdoll
.hipsZZ of the hips of a ragdoll
.ownerNameMultiplayer: the name of the player who drives this object (empty when nobody does, or it is not synced)
.ownerIdMultiplayer: the id of the player who drives this object (0 when nobody does)
.textText shown (text objects)
.visibletrue if visible
.nameObject name
.idUnique id of the instance
.valueSlider / bar value (UI)
.widthWidth of a UI element (what Set size sets)
.heightHeight of a UI element (what Set size sets)
.centerXUI 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
.centerYUI element: where the MIDDLE of its box is drawn, in canvas px from the bottom
.screenXUI 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)
.screenYUI element: where its PIVOT is drawn, in canvas px from the bottom
.minSlider / bar minimum (UI)
.maxSlider / bar maximum (UI)
.pressedUI 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: = ≠ < ≤ > ≥