Game Development Community

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!

About the author

Recent Threads


#1
07/31/2006 (11:10 pm)
For normal functions (not methods on object):

%funcName = "myFunction";
call(%funcName, %arg1, %arg2, ...);

(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.
#2
08/01/2006 (5:39 am)
Eval() FTW! Always saves you ass when you're in dire need for a dirty hack.
#3
08/01/2006 (7:05 am)
Perfect! Thank you very much guys!
#4
08/01/2006 (8:17 am)
Eval() is not evil...eval() is your friend.