Learning about Behaviors
by James Ford · in Torque Game Builder · 04/25/2007 (1:50 pm) · 5 replies
I am learning about behaviors (in the new 1.5) and would like to start a thread where I (and others) can ask questions about behaviors.
I have gone through the tutorial provided on behaviors which is informative on how to create and add behaviors in the level editor, but what about manipulating behaviors in script?
I want to have many different behavior templates available, but I want to add/remove them dynamically during the game. Is the name of a behavior template globally accessible?
For instance I want to do:
MoveToBehavior:OnCollision
{
if (dstObj.class == abc)
%this.owner.addbehavior(blowupBehavior);
}
I have gone through the tutorial provided on behaviors which is informative on how to create and add behaviors in the level editor, but what about manipulating behaviors in script?
I want to have many different behavior templates available, but I want to add/remove them dynamically during the game. Is the name of a behavior template globally accessible?
For instance I want to do:
MoveToBehavior:OnCollision
{
if (dstObj.class == abc)
%this.owner.addbehavior(blowupBehavior);
}
About the author
http://jamesdev.info
#2
adding a behavior:
deleting a behavior (I _think_ this is right, but I haven't tried... so you'll have to do that yourself)
04/28/2007 (3:50 am)
Not entirely sure what it is you're asking, it's definitely possible to add/remove behaviors.adding a behavior:
%behavior = blowupBehavior.createInstance(); %this.owner.addBehavior (%behavior);
deleting a behavior (I _think_ this is right, but I haven't tried... so you'll have to do that yourself)
%behavior = %this.owner.getBehavior("blowupBehavior");
%this.owner.removeBehavior (%behavior);
#3
I'm using %this.owner.removeBehavior ( %this.owner.getBehavior ( "InsertBehNameHere" ) when a certain condition is met inside a onUpdate callback. I've tested the condition by putting an echo when it's met, so the above script is executed since I can see the echos.
The thing is, the echos keep appearing and the behavior keeps happening although it's specifically written t. Any clues on what I may be doing wrong?
07/16/2007 (3:04 pm)
Sorry to revive this, but I'm having a problem.I'm using %this.owner.removeBehavior ( %this.owner.getBehavior ( "InsertBehNameHere" ) when a certain condition is met inside a onUpdate callback. I've tested the condition by putting an echo when it's met, so the above script is executed since I can see the echos.
The thing is, the echos keep appearing and the behavior keeps happening although it's specifically written t. Any clues on what I may be doing wrong?
#4
%behID = %this.owner.getBehavior ( "InsertBehNameHere" );
schedule(1,%this.owner, "removeBehavior", %behID );
I'm not completely sure about those parameters, try it out.
07/17/2007 (9:48 pm)
Is the onupdate within the behavior you want to remove? A behavior can't remove itself. But you can schedule its deletion, like maybe, %behID = %this.owner.getBehavior ( "InsertBehNameHere" );
schedule(1,%this.owner, "removeBehavior", %behID );
I'm not completely sure about those parameters, try it out.
#5
07/18/2007 (2:17 am)
Ah! It's like the onLevelLoaded issue. I'll try it out.
Associate James Ford
Sickhead Games