pub fn choose<S: State, R: 'static, F>(f: F) -> Tree<S, F, R>Expand description
An action that allows implementing a decision tree, with action prioritisation.
The inner function will be run every tick to decide on an action. When an
action is chosen, it will be performed until completed UNLESS an action
with a more urgent priority is chosen in a subsequent tick. choose tries
to commit to actions when it can: only more urgent actions will interrupt an
action that’s currently being performed.
§Example
ⓘ
.choose_mut(|ctx| {
if ctx.npc.is_being_attacked() {
urgent(combat()) // If we're in danger, do something!
} else if ctx.npc.is_hungry() {
important(eat()) // If we're hungry, eat
} else {
casual(idle()) // Otherwise, do nothing
}
})