Skip to content

Commit

Permalink
fixed selector not calling interrupt() (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
lostptr authored Oct 1, 2023
1 parent cf18be7 commit f8912cf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addons/beehave/nodes/composites/selector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func after_run(actor: Node, blackboard: Blackboard) -> void:


func interrupt(actor: Node, blackboard: Blackboard) -> void:
after_run(actor, blackboard)
last_execution_index = 0
super(actor, blackboard)


Expand Down
2 changes: 1 addition & 1 deletion addons/beehave/nodes/composites/selector_random.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func after_run(actor: Node, blackboard: Blackboard) -> void:


func interrupt(actor: Node, blackboard: Blackboard) -> void:
after_run(actor, blackboard)
_reset()
super(actor, blackboard)


Expand Down
27 changes: 27 additions & 0 deletions test/nodes/composites/selector_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const __source = "res://addons/beehave/nodes/composites/selector.gd"
const __count_up_action = "res://test/actions/count_up_action.gd"
const __blackboard = "res://addons/beehave/blackboard.gd"
const __tree = "res://addons/beehave/nodes/beehave_tree.gd"
const __selector_reactive = "res://addons/beehave/nodes/composites/selector_reactive.gd"

var tree: BeehaveTree
var selector: SelectorComposite
Expand Down Expand Up @@ -125,3 +126,29 @@ func test_not_interrupt_first_after_finished() -> void:

selector.remove_child(action3)


func test_interrupt_when_nested() -> void:
var selector_reactive = auto_free(load(__selector_reactive).new())
var fake_condition = auto_free(load(__count_up_action).new())

tree.remove_child(selector)
tree.add_child(selector_reactive)
selector_reactive.add_child(fake_condition)
selector_reactive.add_child(selector)

fake_condition.status = BeehaveNode.FAILURE
action1.status = BeehaveNode.RUNNING

assert_that(tree.tick()).is_equal(BeehaveNode.RUNNING)
assert_that(action1.count).is_equal(1)
assert_that(action2.count).is_equal(0)

fake_condition.status = BeehaveNode.SUCCESS
assert_that(tree.tick()).is_equal(BeehaveNode.SUCCESS)
assert_that(action1.count).is_equal(0)
assert_that(action2.count).is_equal(0)

# clean up...
selector_reactive.remove_child(selector)
tree.remove_child(selector_reactive)
tree.add_child(selector)

0 comments on commit f8912cf

Please sign in to comment.