Logic Puzzles
These puzzles provide conditional expressions to perform different computations or actions depending on whether a condition is met.
![Logic visual programming blocks](files/puzzles/puzzles-logic.jpg)
Contents
Puzzles Reference
if / else
With these puzzles, you can implement branching (control flow) in your puzzles.
![if-else visual programming block](files/puzzles/puzzles-logic-if-else.jpg)
Suppose, you got a cube and a sphere in your scene. When the user clicks on the sphere, you want to hide it, but only if the user has clicked on the cube before. Such a scenario can easily be implemented with a variable for remembering if the cube has ever been clicked:
![if-else example script](files/puzzles/puzzles-logic-example.jpg)
Sometimes you need to compare a variable with multiple values, and thus need more branches. In this case, you can expand the if puzzle by clicking on the gear icon and dragging out more slots: elseif or else.
![Code branching with visual programming](files/puzzles/puzzles-logic-more-branching.jpg)
As a result, you'll be able to fill up the newly created slots with any actions you want to happen in your scenario:
![Complex logic with visual programming](files/puzzles/puzzles-logic-example4.jpg)
comparison
This puzzle compares two values and outputs a logical value as the result of comparison.
![Comparing values in visual logic editor](files/puzzles/puzzles-logic-comparison.jpg)
Instead of explicitely using the true / false values as in the example above, you can leverage any other puzzles such as text to set a value for a variable. In this case, however, you will additionally need the comparison puzzle to be able to check textual values. The result of comparison (true or false) is then supplied to the if / else puzzle:
![Comparing example script](files/puzzles/puzzles-logic-example2.jpg)
Here is a more advanced example: hide the sphere only if the user clicked on the cube 3 times:
![Script with complex visual programming comparisons](files/puzzles/puzzles-logic-example3.jpg)
logical operators AND / OR
You can further detail your comparisons by using the logical AND / OR operators.
![Logical AND/OR visual programming operators](files/puzzles/puzzles-logic-operators-and-or-sample.jpg)
Example:
![Example on using and/or operations](files/puzzles/puzzles-logic-operators-and-or.jpg)
logical operator NOT
You can negate the result of a logical expression (convert true to false and back) by using the logical operator NOT.
![Logical NOT visual programming operator](files/puzzles/puzzles-logic-operator-not-sample.jpg)
Example:
![Example on using NOT operator](files/puzzles/puzzles-logic-operator-not.jpg)
true / false
The logic puzzles operate with only two values, true and false, also known as Boolean values.
![Visual programming block to define boolean values](files/puzzles/puzzles-logic-true-false.jpg)
These values are returned as output by the comparison puzzle, as well as by the logical operators AND / OR and NOT, and supplied as inputs to the branching puzzles if / else and test.
null
The null value, strictly speaking, is not related to logical algebra. If a variable is set to null, it means it is not set to true or false, but rather left "undecided".
![Null visual logic block](files/puzzles/puzzles-logic-null-sample.jpg)
You can use null to explicitely initialize a newly created variable.
![Examples on using uninitialized values in visual programming](files/puzzles/puzzles-logic-null.jpg)
test
Sometimes you can make your puzzles a bit more compact or more convient to use by leveraging the test puzzle which returns value right away.
![Visual programming test operator](files/puzzles/puzzles-logic-test-sample.jpg)
Example:
![Example on using test block](files/puzzles/puzzles-logic-test.jpg)
Having Troubles with Puzzles?
Seek help on the forums!