• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML How to put piece of code in a variable or argument?

Scienitive

Member
Hello, I am trying to put some code into an argument of a script how can I do it?

This is how I want to call the script:
change_script(1, 2, global.military_point = global.military_point + 3, global.economic_point = global.economic_point + 3);

This is inside of the script:

var unique_id = argument[0];
var choice_number = argument[1];
var script0 = argument[2];
var script1 = argument[3];
...


This way is not working.

Is there any way to do it?
 

CloseRange

Member
what do you need to do with it?
There is no way to do what you want and what you put will either return true or false (0 or 1) depending on if they are equal
GML:
global.military_point = global.military_point + 3;
global.economic_point = global.economic_point + 3;
change_script(1, 2, global.military_point, global.economic_point);
the code above will set global.military_point and economic point, then pass them into the script.

Whatever you're trying to do I'm sure IS possible but not by passing code as an argument.
 

Nidoking

Member
You can pass the id of a script and then use script_execute to run it. That's the easiest way to do it. Write every possible "code argument" as a script and pass the script id.
 

TsukaYuriko

☄️
Forum Staff
Moderator
You can't store code in variables right now. This functionality is introduced with the 2.3 beta.

Nonetheless, I do have to ask: What do you need this for? There is likely a simpler solution for it (which would work even now).
 
Top