|
1 | 1 | --- |
2 | 2 | description: | |
3 | | - A Condition Node defines: TODO. |
| 3 | + A Condition Node is useful for selecting the next node based on the result of a combination of conditions. They are a key part of Dialogue Sequences, allowing one to conditionally direct a player through a Dialogue Sequence graph. |
4 | 4 | --- |
5 | 5 |
|
6 | | -A Condition Node defines: TODO. |
| 6 | +A Condition Node is useful for selecting the next node based on the result of a |
| 7 | +combination of conditions. They are a key part of Dialogue Sequences, allowing |
| 8 | +one to conditionally direct a player through a Dialogue Sequence graph. For |
| 9 | +example, deciding which dialogue response to render or choosing whether to |
| 10 | +render a dialogue option (or not). |
| 11 | + |
| 12 | +The output of a Condition Node determines whether the check passed or not. These |
| 13 | +are: |
| 14 | + |
| 15 | +- `true` (green path) - the check passed. |
| 16 | +- `false` (red path) - the check failed. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +They have the following characteristics: |
| 21 | + |
| 22 | +## Description |
| 23 | + |
| 24 | +A human-readable description of the condition node to aid future understanding |
| 25 | +of the node at a quick glance. |
| 26 | + |
| 27 | +## Combiner |
| 28 | + |
| 29 | +The combiner determines whether the combination of conditions pass the overall |
| 30 | +condition check or not. At the moment, Parley supports the following combiners: |
| 31 | + |
| 32 | +- `ALL` - All of the defined conditions must pass for the condition node check |
| 33 | + to pass (a.k.a return `true` (green path)). |
| 34 | +- `ANY` - Any one of the defined conditions must pass for the condition node |
| 35 | + check to pass (a.k.a return `true` (green path)). If some fail, the check will |
| 36 | + still pass provided that one of the conditions has passed. |
| 37 | + |
| 38 | +## Conditions |
| 39 | + |
| 40 | +The conditions to evaluate for the condition node. Each condition contains a |
| 41 | +fact that is compared and they are evaluated and used in conjunction with the |
| 42 | +combiner to determine whether a condition node check has passed or not. See the |
| 43 | +[scenarios](#-scenarios-1) for some examples. |
| 44 | + |
| 45 | +Each condition has the following characteristics: |
| 46 | + |
| 47 | +### Fact Ref |
| 48 | + |
| 49 | +The fact to evaluate for the condition node. These are stored in the fact store |
| 50 | +and at runtime are evaluated for comparison using the defined operator and |
| 51 | +value. |
| 52 | + |
| 53 | +You can think of a fact as something that is exactly what it says on the tin, a |
| 54 | +fact. For example, a fact could be: `Alice gave a coffee`. This fact represents |
| 55 | +whether Alice gave a coffee or not. If this fact evaluated to `true` during the |
| 56 | +running of Parley, then we can say: Alice did indeed give a coffee. However, if |
| 57 | +the fact evaluated to `false`, then we can say: Alice did not give a coffee. |
| 58 | + |
| 59 | +To find out how to define and register a fact, please follow the guide |
| 60 | +[here](../getting-started/register-fact.md). |
| 61 | + |
| 62 | +### Operator |
| 63 | + |
| 64 | +As its name suggests, the operator used to compare the result of a fact against |
| 65 | +the defined value. The following operators are supported: |
| 66 | + |
| 67 | +- `EQUAL` - whether the fact equals the value |
| 68 | +- `NOT_EQUAL` - whether the fact does not equal the value |
| 69 | + |
| 70 | +### Value |
| 71 | + |
| 72 | +The value to compare against the output of the fact using the operator above. |
| 73 | + |
| 74 | +> [tip]: The value will be coerced to match the output type of the evaluated |
| 75 | +> fact where possible. For example, if the fact evaluates to an integer: 2, a |
| 76 | +> value of `3` will be coerced to an integer of `3` for comparison. |
| 77 | +
|
| 78 | +## Scenarios |
| 79 | + |
| 80 | +Below is a list of common scenarios to help you understand how condition nodes |
| 81 | +work. |
| 82 | + |
| 83 | +### Scenario 1 |
| 84 | + |
| 85 | +Let's say the condition node is defined as follows: |
| 86 | + |
| 87 | +Combiner: `ALL` |
| 88 | + |
| 89 | +Conditions: |
| 90 | + |
| 91 | +- Condition 1: |
| 92 | + - Fact: `alice_gave_coffee` |
| 93 | + - Operator: `EQUAL` |
| 94 | + - Value: `true` |
| 95 | + |
| 96 | +When the fact `alice_gave_coffee` evaluates to `true` |
| 97 | + |
| 98 | +The condition node evaluates to `true` and the Dialogue Sequence continues down |
| 99 | +the `true` (green) path only. |
| 100 | + |
| 101 | +### Scenario 2 |
| 102 | + |
| 103 | +Let's say the condition node is defined as follows: |
| 104 | + |
| 105 | +Combiner: `ALL` |
| 106 | + |
| 107 | +Conditions: |
| 108 | + |
| 109 | +- Condition 1: |
| 110 | + - Fact: `alice_gave_coffee` |
| 111 | + - Operator: `EQUAL` |
| 112 | + - Value: `true` |
| 113 | + |
| 114 | +When the fact `alice_gave_coffee` evaluates to `false` |
| 115 | + |
| 116 | +The condition node evaluates to `false` and the Dialogue Sequence continues down |
| 117 | +the `false` (red) path only. |
| 118 | + |
| 119 | +### Scenario 3 |
| 120 | + |
| 121 | +Let's say the condition node is defined as follows: |
| 122 | + |
| 123 | +Combiner: `ALL` |
| 124 | + |
| 125 | +Conditions: |
| 126 | + |
| 127 | +- Condition 1: |
| 128 | + - Fact: `alice_gave_coffee` |
| 129 | + - Operator: `EQUAL` |
| 130 | + - Value: `true` |
| 131 | +- Condition 2: |
| 132 | + - Fact: `bob_has_coffee` |
| 133 | + - Operator: `EQUAL` |
| 134 | + - Value: `true` |
| 135 | + |
| 136 | +When the fact `alice_gave_coffee` evaluates to `true` and the fact |
| 137 | +`bob_has_coffee` evaluates to `true` |
| 138 | + |
| 139 | +The condition node evaluates to `true` and the Dialogue Sequence continues down |
| 140 | +the `true` (green) path only. |
| 141 | + |
| 142 | +### Scenario 4 |
| 143 | + |
| 144 | +Let's say the condition node is defined as follows: |
| 145 | + |
| 146 | +Combiner: `ALL` |
| 147 | + |
| 148 | +Conditions: |
| 149 | + |
| 150 | +- Condition 1: |
| 151 | + - Fact: `alice_gave_coffee` |
| 152 | + - Operator: `EQUAL` |
| 153 | + - Value: `true` |
| 154 | +- Condition 2: |
| 155 | + - Fact: `bob_has_coffee` |
| 156 | + - Operator: `EQUAL` |
| 157 | + - Value: `true` |
| 158 | + |
| 159 | +When the fact `alice_gave_coffee` evaluates to `true` and the fact |
| 160 | +`bob_has_coffee` evaluates to `false` |
| 161 | + |
| 162 | +The condition node evaluates to `false` and the Dialogue Sequence continues down |
| 163 | +the `false` (red) path only. |
| 164 | + |
| 165 | +### Scenario 5 |
| 166 | + |
| 167 | +Let's say the condition node is defined as follows: |
| 168 | + |
| 169 | +Combiner: `ANY` |
| 170 | + |
| 171 | +Conditions: |
| 172 | + |
| 173 | +- Condition 1: |
| 174 | + - Fact: `alice_gave_coffee` |
| 175 | + - Operator: `EQUAL` |
| 176 | + - Value: `true` |
| 177 | +- Condition 2: |
| 178 | + - Fact: `bob_has_coffee` |
| 179 | + - Operator: `EQUAL` |
| 180 | + - Value: `true` |
| 181 | + |
| 182 | +When the fact `alice_gave_coffee` evaluates to `true` and the fact |
| 183 | +`bob_has_coffee` evaluates to `true` |
| 184 | + |
| 185 | +The condition node evaluates to `true` and the Dialogue Sequence continues down |
| 186 | +the `true` (green) path only. |
| 187 | + |
| 188 | +### Scenario 6 |
| 189 | + |
| 190 | +Let's say the condition node is defined as follows: |
| 191 | + |
| 192 | +Combiner: `ANY` |
| 193 | + |
| 194 | +Conditions: |
| 195 | + |
| 196 | +- Condition 1: |
| 197 | + - Fact: `alice_gave_coffee` |
| 198 | + - Operator: `EQUAL` |
| 199 | + - Value: `true` |
| 200 | +- Condition 2: |
| 201 | + - Fact: `bob_has_coffee` |
| 202 | + - Operator: `EQUAL` |
| 203 | + - Value: `true` |
| 204 | + |
| 205 | +When the fact `alice_gave_coffee` evaluates to `true` and the fact |
| 206 | +`bob_has_coffee` evaluates to `false` |
| 207 | + |
| 208 | +The condition node evaluates to `true` and the Dialogue Sequence continues down |
| 209 | +the `true` (green) path only. (Note the `ANY` combiner here). |
| 210 | + |
| 211 | +### Scenario 7 |
| 212 | + |
| 213 | +Let's say the condition node is defined as follows: |
| 214 | + |
| 215 | +Combiner: `ALL` |
| 216 | + |
| 217 | +Conditions: |
| 218 | + |
| 219 | +- Condition 1: |
| 220 | + - Fact: `alice_hit_points` |
| 221 | + - Operator: `EQUAL` |
| 222 | + - Value: `0` |
| 223 | + |
| 224 | +When the fact `alice_hit_points` evaluates to `1` |
| 225 | + |
| 226 | +The condition node evaluates to `false` and the Dialogue Sequence continues down |
| 227 | +the `false` (red) path only. |
| 228 | + |
| 229 | +### Scenario 8 |
| 230 | + |
| 231 | +Let's say the condition node is defined as follows: |
| 232 | + |
| 233 | +Combiner: `ALL` |
| 234 | + |
| 235 | +Conditions: |
| 236 | + |
| 237 | +- Condition 1: |
| 238 | + - Fact: `alice_hit_points` |
| 239 | + - Operator: `NOT_EQUAL` |
| 240 | + - Value: `0` |
| 241 | + |
| 242 | +When the fact `alice_hit_points` evaluates to `1` |
| 243 | + |
| 244 | +The condition node evaluates to `true` and the Dialogue Sequence continues down |
| 245 | +the `true` (green) path only. |
| 246 | + |
| 247 | +## Advanced usage |
| 248 | + |
| 249 | +### Nesting condition nodes |
| 250 | + |
| 251 | +In more complex conditional cases, one may want to nest a series of conditions. |
| 252 | +To achieve this in Parley, you can nest the condition nodes together by |
| 253 | +connecting the output edges to the input of the nested condition nodes. For |
| 254 | +example: |
| 255 | + |
| 256 | + |
0 commit comments