Operators
Operators are the symbols that combine values and conditions. They are useful for scores, gates, and simple game rules.
Math
| Operator | Meaning | Example |
|---|---|---|
| + | Add | $N{Score} + 5.0 |
| - | Subtract | $N{Health} - 1.0 |
| * | Multiply | $N{Score} * 2.0 |
| / | Divide | $N{TimeLeft} / 2.0 |
| % | Remainder | $N{Round} % 2.0 |
Use a calculation as the value you write:
SetVariable('Health', Max($N{Health} - 1.0, 0.0), 0.0)
That subtracts one but never saves a negative health value.
Comparisons
| Operator | Meaning | Example |
|---|---|---|
| == | Is equal to | $TN{FindKey} == 2.0 |
| != | Is not equal to | $TN{OpenDoor} != 1.0 |
| > | Greater than | $N{Score} > 100.0 |
| >= | Greater than or equal | $N{Coins} >= 10.0 |
| < | Less than | $N{TimeLeft} < 30.0 |
| <= | Less than or equal | $N{Health} <= 0.0 |
Remember the task values: 0.0 is Not Active, 1.0 is Active, and 2.0 is Completed.
Combine conditions
| Operator | Meaning | Example |
|---|---|---|
| && | Both must be true | ($N{Keys} >= 1.0) && ($TN{DoorReady} == 1.0) |
| || | Either can be true | ($TN{RouteA} == 2.0) || ($TN{RouteB} == 2.0) |
| ! | Reverse a condition | !($TN{RewardClaimed} == 2.0) |
Use parentheses whenever a rule contains more than one operator:
(($N{Keys} >= 1.0) && ($TN{DoorReady} == 1.0))
|| ($TN{PracticeMode} == 2.0)
Example: allow a reward once
if(
($N{Stars} >= 10.0) && !($TN{RewardClaimed} == 2.0),
SetTask('RewardClaimed', 'Completed', 0.0),
''
)
The numeric task check prevents the action once RewardClaimed has completed. Keep the false branch as an empty string because the true branch returns the result of SetTask().
Common mistakes
- Use == to compare. A single = is not a comparison.
- Do not compare a numeric value to quoted text, such as $N{Score} == '10'.
- Do not use a task-state label in a condition when $TN{Task} gives the numeric state you need.
- Add parentheses instead of relying on readers to guess which part runs first.
See conditions for choosing an outcome and functions for rounding and caps.
