Conditions with if()
Use if() when a rule should make one choice or another. It is the main way to turn a task state or value check into a game action.
if(condition, whenTrue, whenFalse)
A simple condition
if($N{Coins} >= 10.0, 1.0, 0.0)
This returns 1.0 when Coins is at least 10 and 0.0 otherwise. A comparison alone also returns true or false, so use if() when you need different outcomes.
A conditional quest
Suppose FindMap and LightBeacon are tasks, and OpenMountainPath holds the visible effects for the next step.
if(
($TN{FindMap} == 2.0) && ($TN{LightBeacon} == 2.0),
SetTask('OpenMountainPath', 'Active', 0.0),
''
)
The effect runs the true branch only when both prerequisite tasks are Completed.
Keep branch result types compatible
SetTask() and SetVariable() return text describing what they did. If one branch calls one of those helpers, use an empty string in the no-op branch instead of 0.0.
if(
$TN{FindKey} == 2.0,
SetTask('OpenDoor', 'Active', 0.0),
''
)
For a numeric decision, both branches can be numbers:
if($N{Health} <= 0.0, 3.0, 1.0)
Multiple choices: nest if()
Put the next condition in the false branch:
if(
$N{Health} <= 0.0,
SetVariable('WarningLevel', 3.0, 0.0),
if(
$N{Health} <= 25.0,
SetVariable('WarningLevel', 2.0, 0.0),
SetVariable('WarningLevel', 0.0, 0.0)
)
)
Read it from top to bottom: health at or below zero gets the highest warning; otherwise, health at or below 25 gets the second warning; everyone else gets zero.
Triggering a decision at the right time
Use the task or trigger that naturally represents the moment your rule should run. If the rule should update whenever one of its referenced tasks or values changes, enable Trigger On Tasks Change on the Function Effect.
Avoid adding legacy inline change subscriptions to an expression. The supported, inspectable way to re-run a rule is the toggle in the Function Effect settings plus explicit $TN{...} and $N{...} references.
Avoid self-triggering rules
This is risky when Trigger On Tasks Change is enabled:
SetVariable('Score', $N{Score} + 1.0, 0.0)
It watches and changes Score, so it can keep triggering itself. Instead, attach the increment to the event that earns the point, or guard it with a task that changes only once.
Checklist
- Use $TN{Task} values 0.0, 1.0, and 2.0 for task conditions.
- Put each major condition on its own line.
- Keep both outcomes compatible: text with text, number with number.
- Put visible effects on a task such as OpenDoor instead of trying to make one expression control everything.
For score caps and numeric helpers, see functions.
