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.
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.
Torque Owner Adam Larson
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.