executing quoted strings as script
by N.K. · in Torque Game Builder · 10/19/2009 (1:30 pm) · 4 replies
Hi,
I've noticed that the keyboard binding methods take a string holding the snippet of torquescript to execute when that particular key is pressed. Is there a function that allows this to be done in general.
For example can I generate a string holding a function name on the fly and then append semicolons at the end and have the piece of code executed?
Regards
I've noticed that the keyboard binding methods take a string holding the snippet of torquescript to execute when that particular key is pressed. Is there a function that allows this to be done in general.
For example can I generate a string holding a function name on the fly and then append semicolons at the end and have the piece of code executed?
Regards
About the author
#2
That's a dumb example, but generally, yes, you can build a procedural string in script and then evaluate that string using eval().
Edit: Ahhh! Beat to it!
10/19/2009 (1:57 pm)
%string = GameObject @ "." @ %somethingElse @ "+=" @ %anotherVal @ ";"; eval(%string);
That's a dumb example, but generally, yes, you can build a procedural string in script and then evaluate that string using eval().
Edit: Ahhh! Beat to it!
#3
By the way, any idea about how eval() fares in terms of performance since it is in effect performing the functions of a compiler at runtime.
10/19/2009 (2:07 pm)
Thanks a lot.By the way, any idea about how eval() fares in terms of performance since it is in effect performing the functions of a compiler at runtime.
#4
10/19/2009 (2:33 pm)
Necessarily slower than compiled script, depending on how complex the string you feed it.
Torque Owner Max Kielland
MK Development
I use it for debug and log purposes.