Branching¶
Branching runs a different action for each value a capture holds, without writing any script.
A [command.response] table normally has one default action that runs on every
match. To act differently per value, key the table on a capture name instead:
write [command.response.<capture>] and give one entry per value. When the command
fires, Amri looks up the stored value among the keys and runs the matching action.
How it works¶
The keys are the capture's values after synonym resolution, so you
branch on canonical values, not on every spoken variant. A default key acts as
the fallback when no specific key matches. If no key matches and there is no
default, the command logs a warning and does nothing.
An action can be a single string or an array of strings. An array runs in order, which is how you sequence taps and pauses.
Example¶
One command, three outcomes. The target capture picks a weapon, and the optional
value (fire with nothing after it) falls through to default:
[[command]]
name = "Fire Weapon"
description = "Fire the current weapon, or a named one."
category = "combat"
[command.trigger]
pattern = "fire {target:missiles;torpedoes;}"
[command.response.target]
"missiles" = "amri.input.tap('m')"
"torpedoes" = "amri.input.tap('t')"
default = "amri.input.tap('space')"
Say "fire missiles", "fire torpedoes", or "fire" on its own.
Branching versus a value map¶
Both react to the captured value, and they solve different problems:
- Branch when each value runs a genuinely different action: a different key, a different sequence, a different call.
- Use a value map when every value runs the same action string
and only a substituted piece of it changes, for example turning a spoken value
into a key name inside one
amri.input.tap('{value}').
A branch that only differs by one substituted key is usually a map. A map that would need per-value logic is usually a branch.