Skip to main content
Conditions
Updated over a week ago

Conditions are the primary way to use logic in Play. They let you use a trigger to fire different actions in different circumstances.

Conditions are made up of two parts, ‘If’ and ‘Else’, both of which can have their own set of actions. In the If section, you’ll enter an expression that will output a boolean (true or false).

Let’s use the expression example:

variable >= 5.0

If the number variable’s value is indeed greater than 5, this would make the expression’s value true, so the resulting ‘If’ action(s) would fire.

If the variable’s value is less than 5, the expression’s value would be false, so the ‘Else’ action(s) would fire instead. If no actions exist on 'Else', nothing will happen.

You can also create conditions based on object and trigger values. For example, your condition expression might be…

Pan.gestureTranslationX > 0.0

If the user pans right, the pan’s translation X value will be greater than zero, so the card will rotate right 4º. If the user pans left, the the pan’s translation X value will be less than zero, so the card will rotate left -4º.

Creating Conditions in Play

In Play, you’ll add a condition in Interaction Mode. They’re all available in the right-side Interactions Panel and can be dragged onto an object or auto-added by double-clicking. You can add a condition to any trigger.

You can then add an action or group of actions to each section of the condition.

And & Or

You can also check multiple conditions through one condition node using the “and” operator, &&, and the “or” operator, ||. When you use the && operator, all conditions must be true for the expression to output true. When you use the || operator, only one condition out of the list needs to be true to output true.

For example, let's say you're prototyping an online checkout page with an active sale. If a user buys Object A and Object B, they get 15% off.

The condition will check if the quantity of Object A (a variable we'll created for this example) is greater than one, meaning the user was buying Object A. The condition will also check if the quantity of Object B is greater than one.

#quantityObjectA >= 1.0 && #quantityObjectB >= 1.0

The condition will only be true if both expressions are true. Otherwise, the 'Else' actions will fire, even if one of them is true.

Let's say there's a discount code that also gives the user 15% off. We could add a condition to check if that's true.

#codeEntered == “SUMMER24”

Because the discount from entering the code is the same as the quantity discount (15% off), we can merge them using the OR operator (||).

(#quantityObjectA >= 1.0 && #quantityObjectB >= 1.0) || (#codeEntered == “SUMMER24”)

This condition will be true if the user either buys Object A and Object B or enters a discount code. The condition will also be true if both sub-conditions are true.

Nested Conditions

You may encounter a scenario with more than two potential outcomes from a condition. In this case, you’ll set up the condition like usual, but instead of adding an action to the ‘Else’ section, you’ll add another condition. This condition should have a different expression. You can nest an unlimited number of conditions.

For example, let's say you're adding interactions a component, and you want a tap trigger to fire a different action depending on the component’s states. In this case, you would use nested conditions.

Did this answer your question?