Skip to content

Commit 1cdd975

Browse files
committed
Document boolean math sugar
1 parent f50fa92 commit 1cdd975

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [Generators](./api/advanced-scripting/generators.md)
2121
- [Input Groups](./api/advanced-scripting/input-groups.md)
2222
- [Attributes](./api/advanced-scripting/attributes.md)
23+
- [Boolean Math](./api/advanced-scripting/boolean-math.md)
2324

2425
# Tutorials
2526

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Boolean Math
2+
3+
The *Boolean Math* node gives access to common boolean operations, such as `AND`, `NOT`, `XOR`, etc.
4+
5+
However, it can be cumbersome to use the `boolean_math` function in complex boolean expressions.
6+
7+
```python
8+
# Check if the two values equal, or if the first is true.
9+
x = False
10+
y = True
11+
return boolean_math(
12+
operation=BooleanMath.Operation.OR
13+
boolean=(
14+
boolean_math(
15+
operation=BooleanMath.Operation.XNOR # Equal
16+
boolean=(x, y)
17+
),
18+
x
19+
)
20+
)
21+
```
22+
23+
A few operators are available to make boolean math easier and more readable.
24+
25+
```python
26+
# Check if the two values equal, or if the first is true.
27+
x = False
28+
y = True
29+
return (x == y) | x
30+
```
31+
32+
The operators available are:
33+
34+
* `==` - `XNOR`
35+
* `!=` - `XOR`
36+
* `|` - `OR`
37+
* `&` - `AND`
38+
* `~` - `NOT`
39+
40+
> You *cannot* use the built-in Python keywords `and`, `or`, and `not`. You must use the custom operators above to create *Boolean Math* nodes.

0 commit comments

Comments
 (0)