SOLVED Is this a lame way to call a script?


I'm working on another educational game that requires the software to recognize the press of the comma key and the press of the period key. Are these two examples lame ways to call scripts? They both work but I'm unsure about using keyboard_lastchar. I wonder if that will somehow cause problems later, don't ask me how. (I usually read up a bit and then blindly flail until something works, so I'm never totally sure)

if(keyboard_lastchar == ",")script_execute(scr_commaPressed())
if(keyboard_lastchar == ".")script_execute(scr_periodPressed())
Last edited:


Friendly Tyrant
Forum Staff
You don't need the () on the script when you use script execute. Using them means you will be trying to execute the return value of the script and not the script itself. That said what you are doing (when done correctly) is exactly the same as doing this:
if (keyboard_lastchar == ",") scr_commaPressed();
Which (imho) is neater and less to write, so I'd stick with that. Script_execute is really designed for some very specific cases...


King of Raccoons
Script_execute is really designed for some very specific cases...
Personally I've only used Script_execute to make it painfully obvious Im calling a script, I've not found a use for it otherwise

EDIT: Looking at @kburkhart84's response made me remember I also use script execute to call a script dynamically, so yeah there are uses for it lol :p
Last edited:


Firehammer Games
Script_execute is really only best used for when you don't know ahead of time which script is going to be called. You can store a script name in a variable(without parenthesis), and then call that using script_execute(variable). This is useful for things like callbacks(in my case used in my input system), state machines(where you know you are going to call some script depending on the state, but that state changes), and other similar things. If you aren't doing something like that, and your code can know ahead of time what script to call, just do it like Nocturne said.

Also, in 2.3, they have said that script_execute is going to be deprecated. It still works in 2.3, but you will end up wanting to learn the new way functions work, if you are needing the above functionality. The difference is that now in 2.3 you can use the literal variable name with parenthesis to call the function, instead of having to call script_execute(), so script_execute is no longer needed(though they are keeping for at least some unknown time).