Quoted functions as params?
by Yves (Kreegrr) · in Torque Game Builder · 02/10/2006 (1:00 pm) · 5 replies
Hi all,
Is it possible to do the following like you did for non-string params?
From the starter tutorial:
playerMap.bindCmd(keyboard, "w", playerUp(), playerUpStop());
instead of
playerMap.bindCmd(keyboard, "w", "playerUp();", "playerUpStop();"); ?
I get a chill everytime i read a line with a function between quotes with a end of line delimiter inside :)
I wish i didn't have so many years of programming behind me, might be easier to get over it. hehe
Thanks,
Is it possible to do the following like you did for non-string params?
From the starter tutorial:
playerMap.bindCmd(keyboard, "w", playerUp(), playerUpStop());
instead of
playerMap.bindCmd(keyboard, "w", "playerUp();", "playerUpStop();"); ?
I get a chill everytime i read a line with a function between quotes with a end of line delimiter inside :)
I wish i didn't have so many years of programming behind me, might be easier to get over it. hehe
Thanks,
#2
02/10/2006 (3:09 pm)
Just for curiosity why the chills?
#3
I can't speak for Yves, but from a C++ programmer's perspective, it's nonsense. The idea of taking a string and executing it as code is, at best, alien to us.
Obviously it works in TScript (and most other scripting languages), and it's obviously useful, but it is something that long-time C/C++ programers are not at all used to seeing.
02/10/2006 (7:01 pm)
Quote:Just for curiosity why the chills?
I can't speak for Yves, but from a C++ programmer's perspective, it's nonsense. The idea of taking a string and executing it as code is, at best, alien to us.
Obviously it works in TScript (and most other scripting languages), and it's obviously useful, but it is something that long-time C/C++ programers are not at all used to seeing.
#4
Ty for the code snippet!
@Adam
It's exactly like Smaug said, years of debugging in a certain language has your eyes trained to spot things a certain way, i find myselft stopping alot and making sure things are in the right place.
as i get more compfertable in TS, i'll get over it i'm sure.
02/11/2006 (5:03 am)
@David Ty for the code snippet!
@Adam
It's exactly like Smaug said, years of debugging in a certain language has your eyes trained to spot things a certain way, i find myselft stopping alot and making sure things are in the right place.
as i get more compfertable in TS, i'll get over it i'm sure.
#5
I think the "eval" instruction is a very powerfull instruction in TS
it has allowed me to overcome a lot of limitations.
02/13/2006 (11:06 am)
OK I understandI think the "eval" instruction is a very powerfull instruction in TS
it has allowed me to overcome a lot of limitations.
Torque Owner David Bigerstaff
new ActionMap(moveMap); moveMap.bind(keyboard, left, "moveLeft"); moveMap.push(); function moveLeft(%val) { if (%val == 1) echo("key pressed!"); if (%val == 0) echo("key de-pressed"); }The only thing to be careful about with this is that the function will be called when the key is pressed and when it is released.
The good news is that the %val parameter will be 1 or 0 depending on whether the function was called from a key press or key release. ( I thought the values for %val used to be -1 and 1 , but i think that must have changed recently)
I hope that helps.