Game Development Community

How can I refer to an object's behavior / object's behavior field?

by Gonzalo Lopez Mauriño · in Torque Game Builder · 11/01/2009 (2:18 pm) · 1 replies

Hi, first of all thank you very much for any assistance you can give me, as I am a hobby programmer starting to use torquescript (I know C# and Java so It's not my first "language")

Problem is, I have a behavior and I have a class, and a method for that class, for example the button class:




#function ButtonClass::onMouseDown(parameters here){
#
#// Here I would need to access a field *of the behavior* every instance of the ButtonClass has, I've tried
#//lots of things, even looked in the references but I can't find it.
#
#}

Imagine that the behavior has a bool field called "activated79":

# %template.addBehaviorField(activated79, "Toggles activation", bool, false);


And I need to access it from the method onMouseDown of the ButtonClass. I would need either the pointer of the behavior and then the field variable name OR the pointer of the variable itself. I think I kinda explained it by now, It's just difficult for me cause English is not my primary language.

Thanks very much for everything in advance!

About the author

Recent Threads


#1
11/01/2009 (11:40 pm)
To access the behavior of an object, you have to use "getBehavior(<BehaviorName>)".

(Assume the following is in your button's function.)
%behavior = %this.getBehavior( "MyBehavior" );
%behavior.activated79 = true;

Surprisingly, I couldn't find this anywhere on TDN or in the "OFFICIAL DOCUMENTATION" to give you a reference to look at. It's in the "TGB Reference" section of the documentation that comes with TGB 1.7.4, so you can look there for more information.