GameMaker Scripts as Variable Definitions?

Simple question I would think, but is it possible to have a variable definition define a script? So that based on what room you are in (definable in the variable definition "isRoom") you can run that corresponding script? (definable in the variable definition "isScript").

Code:
if (room_exists(isRoom)) { isScript }
When I try something like this I get the dreaded red(x) in the code editor for the "isScript" section.
 

FrostyCat

Redemption Seeker
Use cases like this are invariably dealt with using script_execute().

Set the script into a variable:
Code:
scriptToRun = myScript;
Then later use that with script_execute():
Code:
script_execute(scriptToRun);
 
You are setting sndScript to the value of 0. You need to assign the name of an actual existing script to the the variable sndScript for it to work.

As script names actually resolve to numeric indexes at runtime, setting sndScript to 0 will cause script_execute(sndScript) to run the script with an index of 0. The script with an index of 0 corresponds to the very first (highest script) in your resource tree, rather than the script you want to run.
 
You are setting sndScript to the value of 0. You need to assign the name of an actual existing script to the the variable sndScript for it to work.

As script names actually resolve to numeric indexes at runtime, setting sndScript to 0 will cause script_execute(sndScript) to run the script with an index of 0. The script with an index of 0 corresponds to the very first (highest script) in your resource tree, rather than the script you want to run.
awesome, so that got the script working. For some reason it doesnt work in the next room you go to. No errors or anything just script doesnt seem to be firing.
 
Is there an instance of oBoomBox in the next room? When you change rooms, all instances from the previous rooms are destroyed, unless you check the box in the object properties marked "persistent", or place an instance of oBoomBox in the next room via the room editor.
 
Is there an instance of oBoomBox in the next room? When you change rooms, all instances from the previous rooms are destroyed, unless you check the box in the object properties marked "persistent", or place an instance of oBoomBox in the next room via the room editor.
Yes sir, I have actually tried both methods. I tried the persistent route and the not persistent but in both rooms. Tis perplexing. XD
 

samspade

Member
Have you run the debugger to see if the instance exists and what is going on in general? For example, in the code you posted there are several conditions that have to be fulfilled in order for the script_execute part to run. Have you confirmed that it should be running? For example, what is the value of isRoom after the room change?
 
Assuming that sndScript is set correctly in the next room that you go to, what do you mean by its not working? Have you put a show_debug_message("I'm working") in the script itself to confirm its not running? Also put one in the Async event as well to check that that is firing.

Forgive me if I'm pointing out the obvious here, but also I notice that you are calling audio_group_is_loaded(), but you are not checking the return value for true or false, which is the purpose of that function, it tells you if the audio group is loaded. Your code then sets conditions to true regardless.

Could it be possible that your audio groups haven't loaded yet, and you call the sndScript but it doesn't play sounds because of this?

That's all I can think of for now.
 
Top