Skip to content

Commit f8912cf

Browse files
authored
fixed selector not calling interrupt() (#224)
1 parent cf18be7 commit f8912cf

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

addons/beehave/nodes/composites/selector.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func after_run(actor: Node, blackboard: Blackboard) -> void:
5050

5151

5252
func interrupt(actor: Node, blackboard: Blackboard) -> void:
53-
after_run(actor, blackboard)
53+
last_execution_index = 0
5454
super(actor, blackboard)
5555

5656

addons/beehave/nodes/composites/selector_random.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func after_run(actor: Node, blackboard: Blackboard) -> void:
5757

5858

5959
func interrupt(actor: Node, blackboard: Blackboard) -> void:
60-
after_run(actor, blackboard)
60+
_reset()
6161
super(actor, blackboard)
6262

6363

test/nodes/composites/selector_test.gd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const __source = "res://addons/beehave/nodes/composites/selector.gd"
99
const __count_up_action = "res://test/actions/count_up_action.gd"
1010
const __blackboard = "res://addons/beehave/blackboard.gd"
1111
const __tree = "res://addons/beehave/nodes/beehave_tree.gd"
12+
const __selector_reactive = "res://addons/beehave/nodes/composites/selector_reactive.gd"
1213

1314
var tree: BeehaveTree
1415
var selector: SelectorComposite
@@ -125,3 +126,29 @@ func test_not_interrupt_first_after_finished() -> void:
125126

126127
selector.remove_child(action3)
127128

129+
130+
func test_interrupt_when_nested() -> void:
131+
var selector_reactive = auto_free(load(__selector_reactive).new())
132+
var fake_condition = auto_free(load(__count_up_action).new())
133+
134+
tree.remove_child(selector)
135+
tree.add_child(selector_reactive)
136+
selector_reactive.add_child(fake_condition)
137+
selector_reactive.add_child(selector)
138+
139+
fake_condition.status = BeehaveNode.FAILURE
140+
action1.status = BeehaveNode.RUNNING
141+
142+
assert_that(tree.tick()).is_equal(BeehaveNode.RUNNING)
143+
assert_that(action1.count).is_equal(1)
144+
assert_that(action2.count).is_equal(0)
145+
146+
fake_condition.status = BeehaveNode.SUCCESS
147+
assert_that(tree.tick()).is_equal(BeehaveNode.SUCCESS)
148+
assert_that(action1.count).is_equal(0)
149+
assert_that(action2.count).is_equal(0)
150+
151+
# clean up...
152+
selector_reactive.remove_child(selector)
153+
tree.remove_child(selector_reactive)
154+
tree.add_child(selector)

0 commit comments

Comments
 (0)