Game Development Community

Dynamic function calls??

by Teromous · in Torque Game Builder · 04/12/2008 (1:52 pm) · 3 replies

Is there a way to create dynamic function calls? For instance, if there were a list of functions like:

OneFunction(){ ... }
TwoFunction(){ ... }
ThreeFunction(){ ... }

Then do some sort of code, so that you could do this:

%number @ "Function();"

Then when the string in %number is One, it would call OneFunction(); ?

#1
04/12/2008 (1:54 pm)
eval(%number @ "Function();");
// OR
call (%number @ "Function", %arg1, %arg2, ..., %argN);

=)
#2
04/12/2008 (1:57 pm)
Be sure they're strings and not digits - functions & objects in torquescript cannot be named with a leading digit.
#3
04/12/2008 (2:16 pm)
Thank you Phillip, that is EXACTLY what I am looking for!

Thanks for the tip too Orion.

Everything worked out great!