"loop until success" decorator
mreinstein opened this issue · comments
@Calamari I was looking at your basic inverter decorator which provides a good template for building from, but it's not clear to me how I'd implement this. My assumption is that "loop until success" would only allow one child node, and there would need to be some internal logic in the decorator to handle re-running until success is encountered.
I know this is a fairly specific node type but this might help people like me figure out how to build custom decorators more easily. thoughts?
I am not quite sure I understand, what your decorator should be doing.
If you want a node to run as long as it is not finished. You could probably end the run
method with this.running();
.
Which would start this node first, in the next step. And you could do that until you end either with success
or fail
.
If you would write a Decorator for that, it probably would look like this (if I understood correctly, what you want to achieve):
module.exports = require('./decorator').extend({
success: function() {
this._control.success();
},
fail: function() {
this._control.running();
},
running: function() {
this._control.running();
},
});
And to explain, what happens (and how to use it, which is probably more useful then just giving code):
Every node has a success
, fail
and running
method, which should be used, to end the run
method with. What happens after this, depends on the structure of the tree. In a ordinary Sequence, a success would mean, we call the next node after this one, and a fail would end the running of the Sequence and would straight bubble up the tree to it`s parent (also with a fail). Running would always mean, that this node is not finished yet and should be called first thing on the next AI iteration (as long as you don't write a weird node, that does crazy things with the running).
Basically, when you write a custom decorator, then you will like to override one or more of those methods: fail
, success
or running
. And in those methods you probably would like to call its parent which is available as
this._control`.
Does this help?
thanks for the clarification! Some of this might be great to add to the readme.
I will consider adding this to the Readme.
Glad I could help.