calling a global class in a behavior
by rennie moffat · in Torque Game Builder · 02/18/2010 (3:18 pm) · 8 replies
is this possible? also, I have seen this I believe...
so if I wanted to set a class as a global variable, so I could call it in other behaviors, is that possible? Will it confuse the , SuperClass, Class, Name structure?
what I am thinking...
again, will setting a global inside a behavior be possible...
hmm we shall see...
%this.class $= "ballClass";
so if I wanted to set a class as a global variable, so I could call it in other behaviors, is that possible? Will it confuse the , SuperClass, Class, Name structure?
what I am thinking...
function thisThang::onBehaviorAdd(%this)
{
$thisThangClass = %this.owner.class;again, will setting a global inside a behavior be possible...
hmm we shall see...
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
02/18/2010 (3:38 pm)
ps. I have not coded a simgroup just given a few objets in the scenegraph the same behavior, a class manager.
#3
That actually won't do much, that's how you do a string comparison, so this would work
To do a basic assignment you can just use a regular =... so:
That would effectively set the class field but the linkage only happens when the object is created so doing it after the fact doesn't really help.
Now this does work:
and you can set a global variable anywhere in script, inside a behavior included.
02/18/2010 (3:40 pm)
Just to clarify some things:%this.class $= "ballClass";
That actually won't do much, that's how you do a string comparison, so this would work
if(%this.class $= "ballClass")
{
echo("This class is the Ball Class");
}To do a basic assignment you can just use a regular =... so:
%this.class = "ballClass";
That would effectively set the class field but the linkage only happens when the object is created so doing it after the fact doesn't really help.
Now this does work:
function TestClass::test(%this)
{
echo("BLAH");
}
$class = TestClass;
new ScriptObject(testObj)
{
class = $class;
};
testObj.test();and you can set a global variable anywhere in script, inside a behavior included.
#4
You could save a namespace name anywhere and call any function in it through eval. However, while I have trouble following your description of the problem, this seems like really not the thing you would want to do here.
My recommendation for you is to take an introductory text on programming in an object-oriented language and sit down with that.
02/18/2010 (3:43 pm)
You could save a namespace name anywhere and call any function in it through eval. However, while I have trouble following your description of the problem, this seems like really not the thing you would want to do here.
My recommendation for you is to take an introductory text on programming in an object-oriented language and sit down with that.
#5
is the test function a common function in that,
with it I am calling test, so it does whatever essentially,
but then set class as a global in no function, just in the air so to speak. I am not used to that.
02/18/2010 (3:52 pm)
@matthew, is the test function a common function in that,
with it I am calling test, so it does whatever essentially,
but then set class as a global in no function, just in the air so to speak. I am not used to that.
#6
then i would just use it as is, plug it into a new sciptObject(testObj)
so could this just be an owner of the behavior so in onBehaviorAdd() I just do this...
so now I can call this class globally and if I have an object, with this class applied, if that particular object of the global class set as above and the action applied IF a certain condition is met, ie, is this object mounted. If true,/// as I think here the computer must search all class members. ($starsStarClass)...then...
thanks!
02/18/2010 (4:06 pm)
ps.then i would just use it as is, plug it into a new sciptObject(testObj)
so could this just be an owner of the behavior so in onBehaviorAdd() I just do this...
function thisThangBehavior::onBehaviorAdd(%this)
{
///notice i want to work with behaviors, not sure if that is a factor or not
class = $thisThangClass;
}
//to be clear, in this I need to be sure as how to properly call a class in a behavior.so now I can call this class globally and if I have an object, with this class applied, if that particular object of the global class set as above and the action applied IF a certain condition is met, ie, is this object mounted. If true,/// as I think here the computer must search all class members. ($starsStarClass)...then...
///inside the dismount button a separate object all together
onMouseDown()
{
if(class $= $starsStarClass)
%this.starsStar.dismount()
///i am hoping the computer searches all starsStar on the scenegraph.
///if it finds one it will dismount that starsStar.thanks!
#7
In theory then, could i use a eval in a behaviorField?
so set my class name of importance thru the template?
02/18/2010 (4:14 pm)
@ReneIn theory then, could i use a eval in a behaviorField?
so set my class name of importance thru the template?
#8
02/18/2010 (4:31 pm)
see here I am a bit wobbly, function starDismountBtn::checkIfStarHasItsStar(%this)
{
//must call to all objects of class(or simGroup?)
%starsStarMounted = $starsStarClass.getIsMounted();
///if any member is, I want to allow mouse events to occur
if(%starsStarMounted == true)
%this.owner.setUseMouseEvents(true);
}
function starDismountBtn::onMouseUp(%this)
{
///in here I will dismount, but I am worried that the call will recognize more than just the mounted starsStar
///as it may apply a constant force to all in its class. I dont want that. I just want this command to effect the one starsStar that is mounted to star.
Torque Owner rennie moffat
Renman3000
What I need to do is dismount an objectA if it is mounted to another, however, there are tons of objectA's on the scenegraph at any one time. So the dismount, has to be applied to THAT one objectA and NONE of its kin.
I have ran something like this.
I have a button, a player, and a starsStar (of which there are tons).
Player can pick up starsStar., move it and drop it.
The button is what allows the drop.
The button a t2dSceneObject must recognize that particular starsStar.
I am thinking a class call would be best, but I am unsure as to how to call the class.
:?