Play’s Expression Editor is an input method that allows you to create more advanced, custom interactions. It can be accessed by clicking the + sign button on any property of any interaction node.
When you press the + icon, the Expression Editor will appear as a new window. In the top left, you’ll see the name of the interaction node (i.e. Set State, Animate, Timer, etc.) and the property name (i.e. Value, Start, etc.).
In the top right, you’ll see the mode where you can select if the expression should output as a number, string, or boolean. The mode will update based on the property that opened it. For example, if the property was a Set Opacity action’s value, the mode would default to a number. If it was instead a Set Text action’s value, the mode would default to a string.
The majority of the Expression Editor will resemble a code editor. This is where you’ll write your expression.
Keeping an Expression Editor Open
Usually, an Expression Editor window will be dismissed when you press Enter or click on another node/object. You can keep an Expression Editor open AND pin it to a specific location by dragging it into the desired position. Any number of Expression Editors can be open at once. You can close a pinned Expression Editor by clicking the pin/close button in its top left corner.
Expression Output
When you write something in the Expression Editor, you’ll receive an output. Depending on the value, that output can be a number, string, or bool.
Number Output
A number is a numerical value. If you wrote...
1 + 1
The Expression Editor’s output would be a number with the value 2.
String Output
A string is a sequence of characters, like a word or a phrase. If you wrote...
“I love Play"
or
"I" + " love" + " Play"
The Expression Editor’s output would be a string with the value "I love Play".
Boolean Output
A boolean is a data type that has a value of either true or false.
If you wrote...
"Hello" == "Hello"
The Expression Editor’s output would be a bool with the value True because these strings are the same.
If you instead wrote...
"Hello" == "Goodbye"
The Expression Editor’s output would be a bool with a value False because these strings are not equivalent.
If we used numbers instead of strings, we would see 0 or 1 instead of false or true, respectively.
For example, if you wrote…
1 == 1
The Expression Editor’s output would be a bool with the value 1 because it’s true that one equals one.
Using the Expression Editor
You'll use the Expression Editor for functions, equations, and using object, device, and trigger properties. You can read more about each section by clicking on the links above.