GameMaker Going to Next Room ONLY if it Exists [SOLVED]

I'm making a mobile game where I'll be adding more levels in future updates and I've been trying to figure out how to make it where if the player completes all the levels in the game and there are no levels left, they go to a specific Room instead of the "room_goto_next()".

This code is not real, but this is what I have in mind:

if instance_number(obj) == 0 {
room_goto_next();
} else if room_goto_next() "doesn't exist" {
room_goto(r_end_of_levels_screen);
}

basically, if the player get's though a level and IF there is another level go to it. But, if there is no more levels, go to the room that shows a screen saying that they have reached the end of the levels and to check back for more levels being added in a future update.

I've also tried code like, if room_exists(room) or if room_exists(room_goto_next()).

I know how I could do this by specifying the next room in each room, but it would get tiring manually adding the room variables when eventually I reach over 100 levels.
 
Last edited:
You want !room_exists(room_next(room)) or (room == room_last)
Thank for replying, but I seem to still get the same error I've been getting.

Here's my actual code with the code in your reply:

This is in the Step Event of my o_game Object.

Code:
if global.player_lives < 0 {   
    room_goto(r_gameover);   
}

if instance_number(o_par_block) <= 0 {
    room_goto_next();
} else if !room_exists(room_next(room)) {
    room_goto(r_end_of_rooms);
}
And here's the error I get:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object o_game:

Moving to next room after the last room.
at gml_Object_o_game_Step_0 (line 8) - room_goto_next();
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_o_game_Step_0 (line 8)
 
What I'm wanting to do is check if the next DOESN'T exist. and if it doesn't then go to r_end_of_rooms.

Now for some reason, when I use this code, it causes the game to not even run and the outpt gets stuck on "entering main loop".

Code:
if instance_number(o_par_block) <= 0 && room_exists(room_next(room)) {
    room_goto_next();
} else {
    room_goto(r_end_of_rooms);
}
 
Last edited:
Oddly enough, when I moved my code to the o_player it now works.

I was using it in the o_game because I thought the code should be run in the o_game instead of the o_player.
 
Top