We’re introducing Meta accounts in August 2022: a new way to log into VR devices that doesn’t require a Facebook account. Learn more

IF

Execute the subsequent commands if a defined condition is met.

Appearance in Composition Pane
Description

The codeblocks indented below the if line will execute if the condition evaluates to true. Only booleans are accepted in an if block, however, because logic operators return a boolean, they are also accepted in an if.
Parameters

boolean
If executes the indented codeblocks, if the boolean is true.

Example 1: Execute if a boolean is true

Myboolean here is a boolean variable created in the variables pane. It has previously been set to true, therefore the if statement evaluates to true and executes Debug Print.
Example 2: Execute if a boolean is false

Myboolean here is a boolean variable created in the variables pane. It has previously been set to false. The not logic operator flips a false state to true, therefore the if statement executes when false and runs Debug Print.
Example 3: Toggle a boolean

Set toggle to not (toggle) is an easy way to flip a boolean:

Please note, codeblocks within an event execute simultaneously, and in order. This means that a boolean is recommended to be toggled at the beginning or end of your event, otherwise it can cause other control events to fire unintentionally.
Example 4: Compare two integers

This statement uses the equal-to logic operator ( == ) to compare the values of two number inputs. The if statement evaluates to true and executes the Debug Print codeblock.

Next Up