There are also comparison operators =, <>, <, <=, >, >= for comparing values. They return 1 if the comparison is true or 0 if false.

& also doubles as logical AND, and | is a logical OR operator. These are useful combined with the comparison operators, e.g. score < 0 | health < 0, which also return 1 if true and 0 if false.

?: is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_falsee.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".The condition counts as true if it is non-zero, and false if it is zero.

Strings (text)

Text is also known as strings in programming, and Construct 2 also sometimes uses this naming convention. Text in expressions should be surrounded by double-quotes, e.g. "Hello"

The double-quotes are not included as part of the text, so setting a text object to show the expression "Hello" will make it show Hello, without any double-quotes. To include a double-quote in a string, use two double-quotes next to each other (""), e.g. "He said ""hi"" to me" will return He said "hi" to me.

You can use & to build strings out of mixed text and numbers, e.g. "Your score is: " & score

Standard Mathematical Expressions

The full list of expressions can be found in Construct 2 itself: double-click the System object in the floating expressions panel when you're typing in an expression. However, some common ones are listed here.

Random(N) - Returns a random number between 0 and N, not including N. The result includes fractions, so random(3) can return 2.5. Use floor(random(n)) to generate a random whole number up to but not including N, e.g. floor(random(3))* will return either 0, 1 or 2. Random(A, B) can also be used to generate a random number between A and B.

Don't forget to check the expressions panel in Construct 2 for the full list.

Useful expressions in other objects

Both the Mouse and Touch objects allow you to pass a layer parameter for the X and Y expressions. This is very useful if you scale or rotate layers.

e.g. Mouse.X("Layer 1") returns the mouse's X position on Layer 1, taking in to account its parallax, scale and angle. If you use only Mouse.X, it does not take in to account parallax, scale or angle, so the result can be wrong.

Object indexing in expressions

You can add a 0-based object index to get expressions from different object instances.

e.g. Sprite(0).X gets the first Sprite instance's X position, and Sprite(1).X gets the second instance's X position. You can also pass another expression for the index. Negative numbers start from the opposite end, so Sprite(-1).X gets the last Sprite's X position.

This can be applied to any object expression, not just Sprites.

Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

Hey thanks pearsonlands; I was a little rusty on my coding and I couldn't remember how to mix fixed text and variables in a score readout; After reading thru the tut here, I got everything up and running fine.