Help understanding JSON trees
EnricoPietrocola opened this issue · comments
Hey @Calamari and everyone!
I am making a little graphic editor to make trees for BehaviorTree.js but I think I need to understand better how the JSON files work. Looking at the example in README
{ "type": "selector", "name": "the root", "nodes": [ { "type": "ifEnemyInSight", "name": "handling enemies", "node": { "type": "walk", "name": "go to enemy" } }, { "type": "cooldown", "name": "jumping around", "cooldown": 1, "node": { "type": "jump", "name": "jump up" } }, { "type": "idle", "name": "doing nothing" } ] }
My questions are:
-
I see "nodes" and "node" fields. I understand "nodes" are for branching nodes, but what about "node"? Are they the wrapped node inside a decorator?
-
Are names actually needed?
-
Does everything additional (e.g.) go in the blackboard? Or is that "cooldown":1 field a parameter passed to the node?
Thank you for your help, can't wait to show you guys the editor when I'm finished
Cool, I am curious to see what you will come up with :-)
I am reworking the debugging concept a bit over at #44, maybe that might be useful to you, if you want to viisualize the results of the last step through your tree.
To answer your questions:
- Exactly. Decorators can only decorate one
node
, so the parameter is saying that. For all BranchNodes the parameter isnodes
since they can have multiple. - Names are not needed, but can help while debugging/introspecting a tree.
- The blackboard is a concept to share data between nodes. For example if you have one task that selects the next target to shoot at, and you have a separate shooting-task (which has to know which target to shoot at). The
CooldownDecorator
as I implemented it, takes a config var which represents the cooldown time, that is just for the decorator instance, and not implemented in a blackboard, since you could have multipleCooldownDecorators
with different times.
Does this answer your questions?
Question answered, thank you very much.
I actually decided to revert what I was doing and get my nodes to simply instantiate behaviortreeJS objects instead of trying to make a correct JSON. I'll update as soon as I have a working prototype.
Thanks again