Calamari / BehaviorTree.js

An JavaScript implementation of Behavior Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node.js constructor: use original user parameter instead of destructuring

Joe-Kerr opened this issue · comments

Hi,

Is there any chance for the following change?

(

constructor({ run = NOOP, start = NOOP, end = NOOP, ...props }) {
)

to something like

  constructor(setup) {
    setup.run = setup.run || NOOP;
    setup.start = setup.start || NOOP;
    setup.end = setup.end || NOOP;  
    this.blueprint = setup;
  }

This would have the advantage that User can pass in a class instance while preserving the class context. E.g.

class MyAction {
    
    myMethod() {/*...*/}

    run() {
         this.myMethod() //currently throws "myMethod is not a function"
    }
}

BehaviorTree.register("myAction", new Task( new MyAction() ));

Hi, thanks for the interest.

I am trying to understand what you want to achieve with this. Do I get it right that the main purpose is to be able to make the blueprint an instance of a class, so you can call methods on it?

Why don't you let MyAction inherit from Task directly and just pass an instance of this to the BTree?

On the first glance, it feels weird to pass in a thing called blueprint to make it work as something that should be solved as inheritance. But I am also not quite sure, if I totally get the problem/use case.

Nevermind, does not work as I thought it would. I aplogise for the inconvenience.

No worries :-)