Calamari / BehaviorTree.js

An JavaScript implementation of Behavior Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

debug: true not working

gbarton opened this issue · comments

I've noticed that sometimes my tests will fail if I try to do bTree.step({debug: true}) but they work if I dont enable debug. I get the following exception below:

TypeError: Cannot read property 'map' of undefined
    at t.get (/home/wrk/coordinator/node_modules/behaviortree/dist/index.node.js:1:8666)
    at t.value (/home/wrk/coordinator/node_modules/behaviortree/dist/index.node.js:1:8463)
    at e.value (/home/wrk/coordinator/node_modules/behaviortree/dist/index.node.js:1:4435)
    at Object.route (/home/wrk/coordinator/lib/bt.js:31:542)

I am using 2.0.5 right now. Have you run across this?

Hey, ho.

thanks for the report. That particular error, I did not see before, but I already figured out that there is a problem in the debug part of the BranchNode implementation. It's on my mind to fix it in the near-near future, and I think, since someone else also has problems with it, I will put another "near-" before that. :-)

For that I will have/want to redo the debug implementation.

Ahh ok, so its not necessarily user-error then? :)

In general is there any docs on the debug mode? When it did work it looked like it might give some insight into the node that exited the step (in case of a failure or running return) but I couldnt tell for sure if that's what was happening. Also, I saw that it outputs this when I dump the bTree:

  lastResult: false,
  lastRunData: [
    {
      name: undefined,
      type: 'Sequence',
      nodes: [Array],
      result: false
    }
  ]

I tried adding a name field to my Tasks/Sequences/etc to see if it would populate in the LastRunData area but I couldnt get it to display anything other than undefined.

I'd really like to see a tree representation of how it walked and processed, so maybe a growing array of { name, type, result } values?

Thank you for the reply!

Duely noted. I will add some documentation about this.
Basically, it should print a representation of your tree and tell you which nodes did ran and return which state there were in after the step. If the name is undefined it means, the node did not have a name property assigned. I will also check how I can make the error case more useful in helping out how to resolve it.

Thanks for the response! Is this the right way to name a task? Or is it from using the BehaviorTree.register() method?

const errTask = new Task({
  name: 'errTask',
  run: ({ msg }) => {
    if (msg.err) {
      log('error message detected');
      msg.done = true;
      return FAILURE;
    }
    log('no errors found');
    return SUCCESS;
  },
});

@gbarton That is the right way. If you register something with the BehaviorTree.register method, that is only the name that is used for looking up in the registry. But I get how this might be confusing. Using the BehaviorTree class also as a registry removed the need for a separate BehaviorRegistry class, but separation can help in understanding.

Hmm, maybe I'll add a separate class for that, just add an easy distinguishable way.

btw: I also started working on a new/better way to debug the tree, I just dubbed "introspection". The core of the idea is already, you can see it in the added spec of #44 if you like. Have to polish a bit and clean up old shit :-)

With new version 2.1.0 I dropped the debug: true flag and replaced it with an introspector. Check out the readme for that new goo. That should work better as before :-)

Wow that works like a charm, thank you so much! Really easy to see when it exits the BT now. This will make unit testing also a lot easier to validate as well.

Ty sir!

Thanks. Glad to see it works out :-)