diff --git a/any_test.go b/any_test.go index e085228..29a421c 100644 --- a/any_test.go +++ b/any_test.go @@ -137,7 +137,7 @@ func ExampleAny_resetBehavior() { //1 //failure //1 - //failure behaviortree.Sequence encountered error with child at index 0: some_error + //failure some_error //1 //2 //success @@ -282,7 +282,7 @@ func TestAny_nilChildTick(t *testing.T) { if status != Failure { t.Error(status) } - if err == nil || err.Error() != `behaviortree.Sequence encountered error with child at index 0: behaviortree.Node cannot tick a node with a nil tick` { + if err == nil || err.Error() != `behaviortree.Node cannot tick a node with a nil tick` { t.Error(err) } } diff --git a/selector.go b/selector.go index 9b0add3..ef062b8 100644 --- a/selector.go +++ b/selector.go @@ -16,15 +16,13 @@ package behaviortree -import "fmt" - -// Selector is a tick implementation that will succeed if no children fail, returning running if any children return -// running, propagating any error +// Selector is a tick implementation that ticks each child sequentially, until the the first error (returning the +// error), the first non-failure status (returning the status), or all children are ticked (returning failure) func Selector(children []Node) (Status, error) { - for i, c := range children { + for _, c := range children { status, err := c.Tick() if err != nil { - return Failure, fmt.Errorf("behaviortree.Selector encountered error with child at index %d: %s", i, err.Error()) + return Failure, err } if status == Running { return Running, nil diff --git a/sequence.go b/sequence.go index 23786f4..5aa4931 100644 --- a/sequence.go +++ b/sequence.go @@ -16,15 +16,13 @@ package behaviortree -import "fmt" - -// Sequence is a tick implementation that will succeed if any children succeed, returning running if any children -// return running, propagating any error +// Sequence is a tick implementation that ticks each child sequentially, until the the first error (returning the +// error), the first non-success status (returning the status), or all children are ticked (returning success) func Sequence(children []Node) (Status, error) { - for i, c := range children { + for _, c := range children { status, err := c.Tick() if err != nil { - return Failure, fmt.Errorf("behaviortree.Sequence encountered error with child at index %d: %s", i, err.Error()) + return Failure, err } if status == Running { return Running, nil