This section outlines the expressions in the built-in System object in Construct 2. Many are common mathematical operators, and they can be listed with descriptions in the
Expressions panel, but they are included here for completeness.
This section does not list the operators or syntax that can be used in expressions - just the expressions specific to the System object. For more general information on how to use expressions in Construct 2, see
Expressions.
Display
WindowWidthWindowHeightGet the size of the window. Useful with the
Fullscreen in browser property of the
project, since these enable a variable window size. See also
Supporting multiple screen sizes.
Layers
In expressions where a layer is required, either its name (as a string) or index (as a number) can be entered.
layeropacityGet the opacity (or semitransparency) of a layer, from 0 (transparent) to 100 (opaque).
layerscaleGet the current scale of the layer, not including the overall layout scale.
layerscalerateGet the current scale rate of the layer, which defines how quickly it scales (if at all).
layoutscaleGet the current scale of the entire layout set by the
Set layout scale action. This does not include the scaling of individual layers.
Layout
LayoutWidthLayoutHeightGet the size of the current layout in pixels.
LayoutNameGet the name of the current layout.
scrollxscrollyGet the current position the view is centered on.
Math
These expressions are simply ordinary math functions like you find on calculators. However, note that all functions using an angle take it in
degrees, not radians. Angles start with 0 degrees facing right and increment clockwise.
sin(x),
cos(x),
tan(x),
asin(x),
acos(x),
atan(x) Trigonometric functions using angles in
degrees.
abs(x) Absolute value of x
e.g. abs(-5) = 5angle(x1, y1, x2, y2) Calculate angle between two points
anglelerp(a, b, x) Linearly interpolate the angle
a to
b by
x. Unlike the standard
lerp, this takes in to account the cyclical nature of angles.
anglediff(a1, a2) Return the smallest difference between two angles
anglerotate(start, end, step) Rotate angle
start towards
end by the angle
step, all in degrees. If
start is less than
step degrees away from
end, it returns
end.
ceil(x) Round up x
e.g. ceil(5.1) = 6distance(x1, y1, x2, y2) Calculate distance between to points
exp(x) Calculate e^x
floor(x) Round down x
e.g. floor(5.9) = 5lerp(a, b, x) Linear interpolation of
a to
b by
x.
ln(x) Log to base e of x.
log10(x) Log to base 10 of x.
max(a, b [, c...]),
min(a, b [, c...]) Calculate maximum or minimum of the given numbers. Any number of parameters can be used as long as there are at least two.
pi The mathematical constant pi (3.14159...)
round(x) Round x to the nearest whole number
e.g. round(5.6) = 6sqrt(x) Calculate square root of x
e.g. sqrt(25) = 5System
loopindexGet the index (number of repeats so far) in any currently running loop.
loopindex(name)Get the index (number of repeats so far) of the loop with the given name. Useful for getting indices in nested loops.
objectcountThe total number of objects currently created.
projectversionReturn the version entered in to Project Properties. Note that this is always returned as a string, not a number.
rendererThe name of the renderer used to draw the game, currently either
canvas2d or
webgl. See
Technology for more information on canvas renderers.
Text
find(src, text)Find the first index within
src that
text occurs, else returns -1.
left(text, count)Return the first
count characters of
text.
len(text)Return the number of characters in
text.
lowercase(text)Convert the given text to all lowercase.
mid(text, index, count)Return the
count characters starting from
index in
text.
newlineA string containing a line break. Use to insert line breaks in to strings, e.g.
"Hello" & newline & "World"replace(src, find, rep)Find all occurrences of
find in
src and replace them with
rep.
right(text, count)Return the last
count characters of
text.
tokenat(src, index, separator)Return the Nth token from
src, splitting the string by
separator. For example,
tokenat("apples|oranges|bananas", 1, "|") returns
oranges.
tokencount(src, separator)Count how many tokens occur in
src using
separator. For example,
tokencount("apples|oranges|bananas", "|") returns 3.
trim(src)Return
src with all whitespace (spaces, tabs etc.) removed from the beginning and end of the string.
uppercase(text)Convert the given text to all uppercase.
Time
dtDelta-time in seconds. See
Delta-time and framerate independence.
fpsThe current frames per second (FPS) rate, which is how many times the screen is being drawn every second. Most computers run at 60 fps if they are fast enough.
tickcountThe number of ticks that have run since the game started.
timeThe number of seconds since the game started, taking in to account the time scale.
timescaleThe current time scale.
wallclocktimeThe number of seconds since the game started, not taking in to account the time scale (i.e. the real-world time).
Values
choose(a, b [, c...])Choose one of the given parameters at random. E.g.
choose(1, 3, 9, 20) randomly picks one of the four numbers and returns that. This also works with strings, e.g.
choose("Hello", "Hi") returns either
Hello or
Hi. Any number of parameters can be used as long as there are at least two.
clamp(x, lower, upper)Return
lower if
x is less than
lower,
upper if
x is greater than
upper, else return
x.
float(x)Convert the integer or text
x to a float (fractional number).
int(x)Convert the float or text
x to an integer (whole number).
random(x)Generate a random float from 0 to
x, not including
x. E.g.
random(4) can generate 0, 2.5, 3.29293, but not 4. Use
floor(random(4)) to generate just the whole numbers 0, 1, 2, 3.
random(a, b)Generate a random float between
a and
b, including
a but not including
b.
rgb(r, g, b)Generate a single number containing a color in RGB format. This is useful for conditions or actions taking a color parameter.
str(x)Convert the integer or float
x to a string. Generally not necessary since strings can be built using the
& operator, e.g.
"Your score is " & score