Due to the recent resurgence of spam, we have temporarily disabled user creation and page editing/creation as we resolve the issue.

Booleans

From Snapwiki
Jump to: navigation, search

What is a Boolean

A Boolean is a variable that can only hold a true or false value. A Boolean is sometimes called a binary variable because it can only have one of two possible values.

Terms

Although common in programming and digital circuitry, Boolean variables might be a new topic for many SnapMap players. Some terms are defined below to help clarify.
Boolean: First described by mathematician George Boole, a Boolean is a variable that can have one of two values: true or false. In algebra, you can add, subtract, multiply and divide two numbers to get a result. Similarly in Boolean algebra, you can AND, OR, and XOR two Booleans to get a result.
Toggle: Toggling a Boolean changes the current value (from false to true or from true to false). Toggling is also sometimes called the 'not' or 'negate' operation. Toggle is an input on a Boolean variable object.
Test: On a Gate object, the outputs will not perform their operations unless specifically instructed to by a Test Gate filter. Unlike the On Changed outputs, the outputs of a Gate will not fire whenever their conditions are satisfied.

Using Boolean Filters

You can turn on or off a logic chain based on some condition by using a Boolean Filter.

Add a Boolean Variable. This one is named Condition.
BooleanFilterVariable.PNG

In your desired logic chain, add a Filter between the output and input nodes. In the Boolean Filter's properties, swap in your variable named Condition by hovering over the Boolean property and pressing the Options > Swap Variable/Constant buttons (LEFT CTRL + G on PC, LT + X/Square on console).
BooleanFilterSwapVariable.PNG

In this example, the pressure plate will only open the door when the Condition variable is set to true. The variable can be changed during the match to enable/disable the logic chain as needed.

Boolean Operations and Gates

The Gate object will fire output tests when the Test Gate input is signalled. The output tests will selectively fire based on the values of A and B at the time that Test Gate is signalled.

AND will fire when A and B are both true.
NAND, sometime called Not AND, will fire when A and B are not both true.
OR will fire when either A or B (or both) are true.
NOR, sometimes called Not OR, will fire when neither A or B are true.
XOR, sometimes pronounced exclusive OR, will fire when only one of A or B are true but not when they are both true.
XNOR, sometimes called exclusive Not OR, will fire when A and B are both the same value but not when only one is true.

These binary operations are sometimes summarized in a truth table, which is a listing of all the possible outcomes. Notice that the 'Not' operations NAND, NOR, and XNOR are the negated outcomes of their counterparts AND, OR, and XOR.

Truth Tables
A B AND NAND OR NOR XOR XNOR
False False False True False True False True
False True False True True False True False
True False False True True False True False
True True True False True False False True

The example map YUUNBV3S also has an interactive example of the logic Gate outputs.


Related Pages

You can use a Boolean Messenger to send signals to distant parts of a map.