From 35d0445641fd822a8f3704fe0520c3db568bb7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=8B=E5=85=9A=20Lidang?= Date: Tue, 27 Feb 2024 23:37:21 -0600 Subject: [PATCH] Update Condition Nodes.md --- .../docs/DARC Protocol/Condition Nodes.md | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/darc-docs/docs/DARC Protocol/Condition Nodes.md b/darc-docs/docs/DARC Protocol/Condition Nodes.md index f9067d3..390f139 100644 --- a/darc-docs/docs/DARC Protocol/Condition Nodes.md +++ b/darc-docs/docs/DARC Protocol/Condition Nodes.md @@ -23,12 +23,12 @@ struct NodeParam { There are three logical operators in the DARC protocol: `AND`, `OR`, and `NOT`. The `AND` operator returns true if all of its children are true. The `OR` operator returns true if any of its children are true. The `NOT` operator returns true if its child is false. There must be at least one child for the `AND` and `OR` operators, and only one child for the `NOT` operator. -In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()` functions to create the logical operators, for example: +In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()` wrapper functions to create the logical operators, for example: In darc.js SDK: ```ts -import {and, or, not} from 'darcjs'; +import {and, or, not, AND, OR, NOT} from 'darcjs'; const conditionTree = and( or( @@ -42,6 +42,20 @@ const conditionTree = and( expression4() ) ); + +// or using the class constructor +const conditionTree = new And( + new OR( + expression1(), + expression2() + ), + + expression3(), + + new NOT( + expression4() + ) +); ``` In By-law Script: @@ -59,6 +73,20 @@ const conditionTree = and( expression4() ) ); + +// or using the class constructor +const conditionTree = new AND( + new OR( + expression1(), + expression2() + ), + + expression3(), + + new NOT( + expression4() + ) +); ``` Also you can use `|` for `OR`, `&` for `AND`, and `!` for `NOT` in By-law Script, and these operators will be parsed into the corresponding condition nodes. For example, the above By-law Script can be written as: @@ -70,6 +98,10 @@ const conditionTree = ( ! expression4() ); ``` +### Boolean Values + +There are two boolean values in the DARC protocol: class `TRUE` and clss `FALSE`, or wrapper function `boolean_true()` and `boolean_false()`. They are used to represent a boolean node in the condition tree. + ### Condition Expression 1. There are multiple batch-operations, including: