From 1cdd975dbfdf5c63b550e37b86a83756fc495f5f Mon Sep 17 00:00:00 2001 From: Carson Katri Date: Sun, 20 Nov 2022 18:25:32 -0500 Subject: [PATCH] Document boolean math sugar --- book/src/SUMMARY.md | 1 + .../api/advanced-scripting/boolean-math.md | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 book/src/api/advanced-scripting/boolean-math.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index ebf733e..bfe0e83 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -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 diff --git a/book/src/api/advanced-scripting/boolean-math.md b/book/src/api/advanced-scripting/boolean-math.md new file mode 100644 index 0000000..c62f786 --- /dev/null +++ b/book/src/api/advanced-scripting/boolean-math.md @@ -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. \ No newline at end of file