• 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!

GameMaker Scripts and strings

E

Elgarion

Guest
Hello dear GM community !

I have a little issue with some code, hope some of you will help !

I would like to use strings/arrays to 'remember' the name of a few scripts. See below an example of what I would like to do :

Code:
global.ScriptName_string[1] ="scr_this_is_a_script()" ;
global.ScriptName_string[2] ="scr_what_a_beautiful_script()" ;
then, somewhere else, I would like to call these two scripts

the code below is a complete nonsense, but I hope you will understand what I'm trying to do poorly


Code:
var i;
for (i=1;i<=2 ; i++)
{
// ta-dam ! the scripts 'should' load in order - but here they won't
asset_get_index(string(global.ScriptName_string[i]))
}
Help ! ;-)
 
You're already storing the script name as a string, so you don't need the string() function.

The main issue is you need to drop the "()" parentheses from the script name. asset_get_index just requires the script name without them.

Also, just calling asset_get_index() will just return the index for the script. If you actually want to run the script at that time, you need to call script_execute(script_index);
 
H

Homunculus

Guest
Unless you actually need the script name as a string, you don't really have to store it that way. You can simply store them as assets:

Code:
global.ScriptName_string[1] = scr_this_is_a_script;
global.ScriptName_string[2] = scr_what_a_beautiful_script;
Note the absence of the "()" at the end. The all you need to do is call them using script_execute(your_array_entry) .

Edit: ninja'd
 
Last edited by a moderator:
Top