Calling functions "by name
by Fathom · in Torque Game Engine · 07/31/2006 (10:35 pm) · 4 replies
I basically would like to store the name of a function in a datablock or object field, and be able to call that function when needed without the use of "schedule". For instance using something like this:
function myBehavior(%this) {
// behavior stuff
}
%object.behaviorFunction = "myBehavior";
Now, the only way I know this works is if I use the schedule function, a la:
schedule(0,0, %object.behaviorFunction, %object);
My problem is that schedule seems to call this at the end of a tick (~32ms) and I need it to be called instantly in the event statements following the call are dependant upon its output. Is there a way to achieve this with some other syntax?
Thanks for any help!
function myBehavior(%this) {
// behavior stuff
}
%object.behaviorFunction = "myBehavior";
Now, the only way I know this works is if I use the schedule function, a la:
schedule(0,0, %object.behaviorFunction, %object);
My problem is that schedule seems to call this at the end of a tick (~32ms) and I need it to be called instantly in the event statements following the call are dependant upon its output. Is there a way to achieve this with some other syntax?
Thanks for any help!
Torque 3D Owner Tom Bampton
(you can probably find examples in the existing scripts)
If you want to call methods on objects then you can either add an %obj.call method to SimObject (which would be a really quick and easy job) or use the heinously evil and more-often-misused-then-not piece of crap that is eval(); ;-)
T.