drockon December 15th, 2013 How do we assign a ".name" to behavior?
This function :
object.getBehavior() seems to return either first behavior if no name is specified or crashes if a name is specified.
i've Tried to make if like:
card_behavior = function ()
{
name = "card_behavior";
......
even
card_behavior = function ()
{
behavior.name = "card_behavior";
......
even
CardObj.addBehavior(card_behavior);
card_behavior.name = "card_behavior";
Still
CardObj.getBehavior("card_behavior");
or
CardObj.getBehavior(card_behavior);
returns Null;
Dunno... Maybe i'm just doing it wrong....
drockon December 15th, 2013 Found a more convenient way.. still not realy good one:
this.PlayerHub[0].addBehavior(hero_card);
this.PlayerHub[0]._behaviors[this.PlayerHub[0]._behaviors.length-1].name = 'hero_card';
.....
this.PlayerHub[0].getBehavior('hero_card').DrawStats();
Although it doesn't require to remember order of behaviors adding, i'd still like to have a way to do this without looking into the engine code.
Gio December 15th, 2013 Yeah there is a way, but it isn't really clear from the documentation... I'll update the docs for the next release of WADE. Anyway, in your behavior function, you can do:
card_behavior = function (){this.name = "card_behavior";.....so "name" should be a member of the behavior function. Then you can do:
this.PlayerHub[0].getBehavior('card_behavior');
drockon December 15th, 2013 Thx, seems i missed that way when tried to assign name )