Game Development Community

Questions about behaviors

by Kodafox · in Torque Game Builder · 04/01/2007 (6:47 pm) · 3 replies

Hello,
I think the new behaviors construct is great. It seems really useful. I was thinking about how to take advantage of behaviors and I came up with a question. Can behaviors be assigned dynamically to objects that are created in script? And if so would it be recommended or is there a better way to achieve similar effects. It seems to me that you may know ahead of time that certain classes in your game may all share cross-cutting functionality that you could take out of the individual namespaces and put into one behavior that you would then apply to every instance of those classes. I'm not sure if I'm even making sense because I'm a little cloudy on how these things work. That's why I wanted to come ask some of your ideas on using behaviors.

#1
04/01/2007 (7:03 pm)
Yep, you can assign behaviors dynamically. That would be done like this:

%behavior = MyBehavior.createInstance();
   %sceneObject.addBehavior(%behavior);

Where MyBehavior is the name you give the BehaviorTemplate when you create it.

Another option would be adding the behavior when the object is created and have an 'enabled' flag on it. Then, in all the callbacks, check if the behavior is enabled and early out if it isn't. I haven't decided yet which of these methods I like better.

I'll be writing up something tomorrow that explains behaviors in more detail.
#2
04/01/2007 (10:20 pm)
Cool looking forward to the behaviors info!
#3
02/10/2010 (11:35 am)
I have a question related to this....

can multiple objects share the same behavior? I am thinking yes but currently object 1 works in my demo but not object 2.


:?