getBehavior
drockon

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....
All 4 Comments
drockon
Well Found a way:
this.PlayerHub[0]._behaviors[1].DrawStats();
 
That way code works but it means i have to hold in mind in wich order do i assign behaviors and never change this order.
drockon

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

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

Thx, seems i missed that way when tried to assign name )

Post a reply
Add Attachment
Submit Reply
Login to Reply