Game Development Community

Behavior question

by Robert Hanz · in Torque Game Builder · 10/11/2009 (2:45 am) · 3 replies

So, I've got one behavior that allows an object to take damage and die. I'd like to encapsulate the effect of dying in another behvaior on the same object, so that they can vary independently. However, calling %this.owner.<method> doesn't seem to get delegated to behaviors the same way as calling %arbitraryObject.<method> seems to

So, I could add the code to do what I want to do on death to the behavior directly, but, as I said, I'd prefer not to combine those responsibilities into a single behavior.

Is there any way to do what I'm attempting?

About the author

Programmer - used to work in game industry. Now, not so much, but it's in the blood.

Recent Threads


#1
10/11/2009 (6:03 am)
sorry its late for me and my brains unfocused but Im not sure what your trying to do? Make it play an effect on death or play 2 effects on death?
#2
10/11/2009 (6:08 am)
To access a behavior of an object, you'll need to use something like the following:
%otherBehavior = %this.owner.getBehavior( DyingBehavior );
Once you have that, you can call the behavior's functions on "%otherBehavior", like "%otherBehavior.<behaviorMethod>()". I assume this is what you're trying to do.

If you wanted to get really fancy and have different dying behaviors, you could add a field to your current behavior where you give it the name of the death behavior. Your current behavior would new up the behavior for your "owner" and then it would also have the name for the "getBehavior" call. Just a thought!
#3
10/11/2009 (4:55 pm)
What I was really hoping for was something more like the Aggregate design pattern, where I could be loosely coupled from the handler of the Behavior.

I'll play with this some more, thanks!