Document boolean math sugar

This commit is contained in:
Carson Katri 2022-11-20 18:25:32 -05:00
commit 1cdd975dbf
2 changed files with 41 additions and 0 deletions

View file

@ -20,6 +20,7 @@
- [Generators](./api/advanced-scripting/generators.md)
- [Input Groups](./api/advanced-scripting/input-groups.md)
- [Attributes](./api/advanced-scripting/attributes.md)
- [Boolean Math](./api/advanced-scripting/boolean-math.md)
# Tutorials

View file

@ -0,0 +1,40 @@
# Boolean Math
The *Boolean Math* node gives access to common boolean operations, such as `AND`, `NOT`, `XOR`, etc.
However, it can be cumbersome to use the `boolean_math` function in complex boolean expressions.
```python
# Check if the two values equal, or if the first is true.
x = False
y = True
return boolean_math(
operation=BooleanMath.Operation.OR
boolean=(
boolean_math(
operation=BooleanMath.Operation.XNOR # Equal
boolean=(x, y)
),
x
)
)
```
A few operators are available to make boolean math easier and more readable.
```python
# Check if the two values equal, or if the first is true.
x = False
y = True
return (x == y) | x
```
The operators available are:
* `==` - `XNOR`
* `!=` - `XOR`
* `|` - `OR`
* `&` - `AND`
* `~` - `NOT`
> You *cannot* use the built-in Python keywords `and`, `or`, and `not`. You must use the custom operators above to create *Boolean Math* nodes.