Document boolean math sugar

pull/10/head
Carson Katri 2022-11-20 18:25:32 -05:00
rodzic f50fa922be
commit 1cdd975dbf
2 zmienionych plików z 41 dodań i 0 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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.