Calamari / BehaviorTree.js

An JavaScript implementation of Behavior Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

  1. 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?

  2. Are names actually needed?

  3. 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

Hi @EnricoPietrocola.

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:

  1. Exactly. Decorators can only decorate one node, so the parameter is saying that. For all BranchNodes the parameter is nodes since they can have multiple.
  2. Names are not needed, but can help while debugging/introspecting a tree.
  3. 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 multiple CooldownDecorators 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