Added enter() and exit() methods for beehave nodes#126
Conversation
- Added `enter()` and `exit()` methods in BeehaveNode. - Adjusted some composites to use those methods now - Since it's the parent's responsability to call those methods, all tests needed to be adjusted so that a `BeehaveTree` is added as the root. - Some tests needed adjustments because now decorators **will** throw errors if they have no children. - A new test was added to validade the enter and exit methods. - A new test action was added to make those tests possible.
|
Great PR! We may want to be a bit more specific about the naming of the methods, as it is currently not quite clear when
This makes it sound that the Could you also add something to the |
How about
Oh yes! Forgot about that |
|
@lostptr good suggestion. Mhhh. I was first thinking about before_tick and after_tick but that would technically be wrong, right? |
|
Yes, that would be wrong. I was thinking of giving an example in the documentation but maybe that's too much...?
Something along the lines... |
|
@lostptr I think that's great! Also, sorry for the merge conflict <3 |
- A short explanation of those methods was also added in the README.
…into feat/enter-exit
* Fix: Check child count before applying interrupt So it doesn't throw an error, when: - there's no child node inside the BeehaveTree - the BeehaveTree is disabled * Add duck typing check for interrupt method in child * 🧪 Add Trees to UnitTestScene to cause errors if fix is not applied * EmptyTree A tree, that is activated and has no children * OnlyOneActionTree A tree with only one action in it * DeactivatedTree A tree that is deactivated --------- Co-authored-by: miguel <miguel-gonzalez@gmx.de>
…into feat/enter-exit
|
@bitbrain ok yeah this messes everything lol Now the beehave tree root is a weird composite that just runs everything without a care. for child in get_children():
if child is BeehaveNode:
status = child.tick(actor, blackboard)Why is this needed? Alternatively, that "execute" implementation would require very minimal changes because all of the code would be handled inside the node itself, not their parent. I substancially reduces coupling and make it much easier to create new composites since there will be no need to think where to put the With the current implementation, we introduce some constraints:
That's why I had to make so many changes :/ Now consider what would need to be established with the "execute" implementation:
Thats it. In fact, none even needs to know that this method exists! It is only relevant when you create Composites or Decorators and even then, all you need to know is that you have to call |
|
@lostptr that was just an attempt to safely run its only child as it can happen that someone adds no children to a tree but disabling it may not be a good idea as folks may want to add child nodes at runtime. What you are describing though should be still correct: BeehaveTree should only ever have one child at max. Perhaps replacing the for loop with if check + get_child(0) might be better after all. |
|
@lostptr thank you! |
…118 * Added `enter()` and `exit()` methods for beehave nodes - Added `enter()` and `exit()` methods in BeehaveNode. - Adjusted some composites to use those methods now - Since it's the parent's responsability to call those methods, all tests needed to be adjusted so that a `BeehaveTree` is added as the root. - Some tests needed adjustments because now decorators **will** throw errors if they have no children. - A new test was added to validade the enter and exit methods. - A new test action was added to make those tests possible. * Changed `enter` and `exit` to `before_run` and `after_run` - A short explanation of those methods was also added in the README. * Fix: Check child count before applying interrupt (#121) * Fix: Check child count before applying interrupt So it doesn't throw an error, when: - there's no child node inside the BeehaveTree - the BeehaveTree is disabled * Add duck typing check for interrupt method in child * 🧪 Add Trees to UnitTestScene to cause errors if fix is not applied * EmptyTree A tree, that is activated and has no children * OnlyOneActionTree A tree with only one action in it * DeactivatedTree A tree that is deactivated --------- Co-authored-by: miguel <miguel-gonzalez@gmx.de> * 🐛 do only unregister monitor when present (#128) * Update addons/beehave/nodes/beehave_tree.gd --------- Co-authored-by: miguel <miguel-gonzalez@gmx.de> Co-authored-by: Patrick Werner <paddi@tastenklopfer.io>

Description
Many things had to be changed:
enter()andexit()methods inBeehaveNode.BeehaveTreeis added as the root.MockAction)Addressed issues
#117