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

[SOLVED] game_restart() not triggering the first time

C

Carcophan

Guest
Hello everyone.

My code, below, seems to be triggering two message boxes, and 'ignoring' the game_restart() code. I am still learning the finer details, but what am I doing wrong here??

I am experiencing TWO message boxes, a '1' and a '4' for example. Sees like '4' should never trigger if '1' was first triggered. Is there a speed/timing issue or something? I also don't understand how a collision can occur twice in general, let alone how the restart is skipped.

Psudo code:
Code:
x += x_speed_;
if(x_speed_ > 0) {  //collision right side
   
        if(cx = 17){
            show_message("1");   
            game_restart();  //not triggering, before '4' is triggered
        } else {
      //other code
            }       
        }
} else if x_speed_ < 0 {  //collision left
   
    if(cx = 17){
        show_message("2");   
        game_restart();
    } else {
       //other code
        }
    }
}

y += y_speed_;
if y_speed_ > 0 {
   
    if(cx = 17){
        show_message("3");   
        game_restart();
    } else {
     //other code
    }
} else {
           
    if(cx = 17){
        show_message("4");   
        game_restart();
    } else {
        //other code
    }
}
 

samspade

Member
game_restart is only going to trigger if cx == 17. I don't see any code that says where cx is set.

While I don't see it in the manual it is also possible that game_restart doesn't trigger until the end of the event/script that it is running in. So in this case you would get two debug messages. A simple test of this second option would be to add exit after game restart. So every place game_restart occurs should look like this:

Code:
game_restart();
exit;
 

CloseRange

Member
I'm not sure why it doesn't show for game restart. But yes when calling game_restart it will first finish executing the current step before actually restarting.
it's the same for game_end function:
This will not happen instantaneously, but rather at the end of the current step, so any code you have in the same step after this function has been called will still run.
That SHOULD be in the game_restart event too, but it is not for some reason.
 
C

Carcophan

Guest
Yes, CX is set, but I didn't include it in this example by mistake. The code (17) does trigger, but twice.

Exit does seem to have corrected the problem for now. I didn't realize that end_game was different than exit until just now. Thanks.
 

CloseRange

Member
Yes, CX is set, but I didn't include it in this example by mistake. The code (17) does trigger, but twice.

Exit does seem to have corrected the problem for now. I didn't realize that end_game was different than exit until just now. Thanks.
game_end will stop the game from running all together.
exit will exit the currently running script block.
you were having problems because game_restart waits till the step event completes before actually resetting so exit is just a way to bypass that and leave the code anyway.
 
Top