Legacy GM game hangs

Y

Yvalson

Guest
So i'm trying to get my wave system to work. but when I start my game it will just hang whenever I press the start button
the code for the wave is as followed as I think it's related to the spawning of instances which has caused me same kind of problems before. anyway here is the code maybe someone can see why it keeps hanging.

Code:
Last_Pause ++

if(Last_RSpider = 3){
CurR_Spiders = ++
Last_RSpider = 0
}

if(Last_BulletRain = 4){
CurBulletRains = ++
Last_BulletRain = 0
}

if(Last_Bomb = 2){
CurBomb = ++
Last_Bomb = 0
}

var i;
for(i = 0; i < CurSpiders / 5; i++){
    Spider = instance_create(irandom_range(0, room_width), random_range(0, room_height), Obj_Spider)
}

var l;
for(l = 0; l < CurR_Spiders; l++){
    RSpider = instance_create(irandom_range(0, room_width), random_range(0, room_height), Obj_Spider_Ranged)
}

var p;
for(p = 0; p < CurBomb; p++){
    Bomb = instance_create(irandom_range(0, room_width), random_range(0, room_height), Obj_Bomb)
}

var q;
for(q = 0; q < CurBulletRains; q++){
    BulletRain = instance_create(irandom_range(0, room_width), random_range(0, room_height), Obj_BulletRain)
}
Alarm_Set = 0
 
In what object and event are you running this code?

Why are you assigning the value returned from instance_create to a variable inside those for() loops. I ask because the variable will be being overwritten with each cycle of the loop, and you are not doing anything else with that variable, so it is redundant.

Check all the objects that you are using in your code. Do any of them also call instance_create() in their Create Event? This can cause an infinite loop and cause your game to crash.

For example, if your obj_BulletRain has in its Create Event code that also creates more obj_BulletRain, that would lock up your game.
 
Y

Yvalson

Guest
this code is ran in a alarm event triggered from the step event. which uses a while loop to repeat this alarm 5 times
I Don't know either I just did will remove that I think I did for myself to know what instance it was creating.
alright I will check my code I probably made an infinity loop somewhere (probably in the while)
 
while() loops are notorious (at least for me) at creating infinite conditionals.

which uses a while loop to repeat this alarm 5 times
This sounds suspicious to me...if you still have problems, post that code from your step event so we can have a look.
 
Y

Yvalson

Guest
while() loops are notorious (at least for me) at creating infinite conditionals.



This sounds suspicious to me...if you still have problems, post that code from your step event so we can have a look.
I can't get it to work here is the code for the while loop:

Code:
while(Last_Pause != 5){
    if(Alarm_Set = 0){
        Alarm[0] = 600
        Alarm_Set = 1
    }
}

alarm[1] = 1500
 
Ah hah! We have the culprit!

The thing with while loops is that when a while loop is running...absolutely nothing outside of the while loop is running. No alarms will be triggering, no events etc....your entire game will be sitting around twiddling its thumbs waiting for good ol' Mr. While loop to do its business.

The only code running will be whats inside the while loop, over and over again.

And if that loop never stops - thats when you will see your whole game just freeze and do nothing "while" happily waiting for the end that never comes :)

You have written :

while (Last_Pause != 5 )

as the exit condition for the loop.

And inside the loop, there is nothing that will change the value of Last_Pause.

I see you are setting alarms inside the while loop, but again, these will not make any alarms trigger, it will just set the value for the alarm over and over again...but because we are in the while loop, the alarms never have a chance to count down, and thus never be triggered.

So, one of two things will happen...:

1) if Last_Pause == 5 - the loop will check the condition at the start, see that Last_Pause *does* equal 5, and the loop will not run at all because the exit condition is already met.

2) if Last_Pause != 5 - the loop will start running....and never stop...because the value of Last_Pause is never changed inside the loop, it will never cause the loop to exit, because the exit condition is never TRUE.

The alarm won't be triggered because they don't get updated until the while loop finishes of course.

If you want something to trigger the alarm 5 times, you might want to do something like this:

Note this is probably not optimal code, but I tried to keep it simple and similar to what you have written above.

Step Event
Code:
if ( Last_Pause < 5 ) // If we haven't triggered the alarm 5 times yet...
{
    if ( alarm[0] < 0) // And if alarm[0] is not currently counting down
    {
        alarm[0] = 600 // Set the alarm timer
        Last_Pause++ // Increase the count of the number of times we have run the alarm
    }
}
I'm not sure Last_Pause is the best variable name, I just used it as its what you seem to be using to track the number of times the alarm gets triggered.
 
Y

Yvalson

Guest
Ah hah! We have the culprit!

The thing with while loops is that when a while loop is running...absolutely nothing outside of the while loop is running. No alarms will be triggering, no events etc....your entire game will be sitting around twiddling its thumbs waiting for good ol' Mr. While loop to do its business.

The only code running will be whats inside the while loop, over and over again.

And if that loop never stops - thats when you will see your whole game just freeze and do nothing "while" happily waiting for the end that never comes :)

You have written :

while (Last_Pause != 5 )

as the exit condition for the loop.

And inside the loop, there is nothing that will change the value of Last_Pause.

I see you are setting alarms inside the while loop, but again, these will not make any alarms trigger, it will just set the value for the alarm over and over again...but because we are in the while loop, the alarms never have a chance to count down, and thus never be triggered.

So, one of two things will happen...:

1) if Last_Pause == 5 - the loop will check the condition at the start, see that Last_Pause *does* equal 5, and the loop will not run at all because the exit condition is already met.

2) if Last_Pause != 5 - the loop will start running....and never stop...because the value of Last_Pause is never changed inside the loop, it will never cause the loop to exit, because the exit condition is never TRUE.

The alarm won't be triggered because they don't get updated until the while loop finishes of course.

If you want something to trigger the alarm 5 times, you might want to do something like this:

Note this is probably not optimal code, but I tried to keep it simple and similar to what you have written above.

Step Event
Code:
if ( Last_Pause < 5 ) // If we haven't triggered the alarm 5 times yet...
{
    if ( alarm[0] < 0) // And if alarm[0] is not currently counting down
    {
        alarm[0] = 600 // Set the alarm timer
        Last_Pause++ // Increase the count of the number of times we have run the alarm
    }
}
I'm not sure Last_Pause is the best variable name, I just used it as its what you seem to be using to track the number of times the alarm gets triggered.
thanks man I'll try it out. and about Last_Pause the name comes from this. with last_pause i check how many repeats it took since the last pause was active
 
Y

Yvalson

Guest
Ah hah! We have the culprit!

The thing with while loops is that when a while loop is running...absolutely nothing outside of the while loop is running. No alarms will be triggering, no events etc....your entire game will be sitting around twiddling its thumbs waiting for good ol' Mr. While loop to do its business.

The only code running will be whats inside the while loop, over and over again.

And if that loop never stops - thats when you will see your whole game just freeze and do nothing "while" happily waiting for the end that never comes :)

You have written :

while (Last_Pause != 5 )

as the exit condition for the loop.

And inside the loop, there is nothing that will change the value of Last_Pause.

I see you are setting alarms inside the while loop, but again, these will not make any alarms trigger, it will just set the value for the alarm over and over again...but because we are in the while loop, the alarms never have a chance to count down, and thus never be triggered.

So, one of two things will happen...:

1) if Last_Pause == 5 - the loop will check the condition at the start, see that Last_Pause *does* equal 5, and the loop will not run at all because the exit condition is already met.

2) if Last_Pause != 5 - the loop will start running....and never stop...because the value of Last_Pause is never changed inside the loop, it will never cause the loop to exit, because the exit condition is never TRUE.

The alarm won't be triggered because they don't get updated until the while loop finishes of course.

If you want something to trigger the alarm 5 times, you might want to do something like this:

Note this is probably not optimal code, but I tried to keep it simple and similar to what you have written above.

Step Event
Code:
if ( Last_Pause < 5 ) // If we haven't triggered the alarm 5 times yet...
{
    if ( alarm[0] < 0) // And if alarm[0] is not currently counting down
    {
        alarm[0] = 600 // Set the alarm timer
        Last_Pause++ // Increase the count of the number of times we have run the alarm
    }
}
I'm not sure Last_Pause is the best variable name, I just used it as its what you seem to be using to track the number of times the alarm gets triggered.
changed it and now it works. thank you man, never using while loops again they always mess up my projects
 
You're welcome.

while() loops do have their uses, just need to make 100% sure that they will finish.

Most of the time when I use a while() I add what I call a "safety check" to make sure it has a way to stop if something went wrong

For example:
Code:
var safety_check = 100 // Maximum number of times to run the loop before emergency stopping.

while ( <some_condition > )
{
    safety_check--
    if ( safety_check < 0 )
    {
        show_debug_message("Warning : Emergency exit of while loop occurred!")
        break; // Force stopping of while loop
    }

    <normal while loop code goes here>
}
 
Y

Yvalson

Guest
You're welcome.

while() loops do have their uses, just need to make 100% sure that they will finish.

Most of the time when I use a while() I add what I call a "safety check" to make sure it has a way to stop if something went wrong

For example:
Code:
var safety_check = 100 // Maximum number of times to run the loop before emergency stopping.

while ( <some_condition > )
{
    safety_check--
    if ( safety_check < 0 )
    {
        show_debug_message("Warning : Emergency exit of while loop occurred!")
        break; // Force stopping of while loop
    }

    <normal while loop code goes here>
}
thanks man I'll keep that in mind
 
Top