GameMaker Game Sometimes Runs/Doesn't Run/Only Runs Audio

Chris Smith

Member
Greetings friends,
Out of nowhere my game started to fail to run, even though the output window doesn't show a failure. It sometimes doesn't reach the main loop. But sometimes it does reach the main loop, but only plays the audio. Sometimes it runs fine.

Everything was running fine, until I added a segment of Draw_GUI code. But I've commented out that code, and it does the same thing. So, I'm wondering if maybe there's a problem with GameMaker right now, or if anyone has experienced this? Maybe I accidentally changed a setting with a key combination? Maybe I did something dumb without realizing?

As always here's a video of the issue in action.
Thanks all!
 

Nidoking

Member
You probably need to debug. Click the left side of some lines to set breakpoints, hit the Debug button instead of Run to run the program, and see which breakpoints get triggered, and which don't. Stepping through line by line might help you figure it out. I assume it's something about the order in which instances are created, or something like that which can happen in different orders each time you run the game.
 
I could have a look at it and see if I can find anything wrong if you wanted to DM me a link to your project, however I fully understand if you don't want to give out your project source.
 

Chris Smith

Member
Thanks everyone, since responses were light here, I went to Facebook, and was told how to debug there, and found that a couple sections with while loops on the very first step of the game were getting stuck.

What really threw me was that those while loops didn't get stuck the first several times being run. Like several dozen times. But that's just the nature of RNG I guess, the first several dozen times, when these loops reached the third loop, they didn't need to loop, and they just passed through. But now 9/10 times or more they would get stuck.
It was just a dumb incorrect variable, in the exact same spot on both sections.

The reason I would get audio sometimes, and nothing other times, is because There is a set of while loops early in the create event of the obj_game_settings, then after I have a 1-step alarm with another set of them. after the alarm is set, I then play the audio at the end of the create event, so the alarm goes off after that. So if the game gets stuck on the first set of loops, I get no audio. If the game gets stuck on the second set of loops, I do get audio.
💩💩💩💩1.PNG 💩💩💩💩2.PNG
 

Nidoking

Member
For reference, this is how I would handle what you're doing there without while loops:
Create a list, then put the four numbers you generate into the list. Since you're using all four numbers, you can just shuffle the list, then assign the variables whatever value ends up in the corresponding position in the list.

Code:
var OptionList = ds_list_create();
ds_list_add(OptionList, irandom_range(25, 49);
ds_list_add(OptionList, irandom_range(50, 74);
//etc.

ds_list_shuffle(OptionList);
joy_mult = OptionList[|0];
health_mult = OptionList[|1];
protection_mult = OptionList[|2];
love_mult = OptionList[|3];

ds_list_destroy(OptionList);
That still works if you're using only some of the numbers, but another thing I like to do to exclude certain values is to remove them from the list before shuffling. You could also randomly index into the list, grab the value, then remove it from the list before selecting the next value. That might look like this:

Code:
var OptionList = ds_list_create();
ds_list_add(OptionList, irandom_range(25, 49));
ds_list_add(OptionList, irandom_range(50, 74));
//etc.

var index = irandom(ds_list_size(OptionList) - 1);
joy_mult = OptionList[|index];
ds_list_delete(OptionList, index);
// The selected option has now been removed from the list
index = irandom(ds_list_size(OptionList) - 1);
health_mult = OptionList[|index];
ds_list_delete(OptionList, index);
//etc.

ds_list_destroy(OptionList);
 
Top