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

Legacy GM Room Transition Problems

Avram

Member
I have some very odd behaviour happening when I'm switching from one room to another in a platform game I've been working on for far too long.
Here's a list of the rooms I currently have:

GAME SETUP
1. room_initialize - sets up some initialization code and goes straight to next room
2. room_title - title screen
3. room_levels - level select screen
4. room_settings - allows for adjustment of onscreen controls
5. room_about - credits

LEVELS
6. room_begin_001 - first level
7. room_first_big_room_002
8. room_bouncy_003
9. room_tall_004
etc.

I discovered that I can use numbers instead of room names to progress to certain levels and so I have a variable that keeps track of where the player has reached - global.level_reached. In the set-up, the value is 5 (so that the game begins at 6. room_begin_001).

The first odd thing is that when I have the player complete a room which is achieved by touching an end-of-level object the game jumps TWO levels whilst only increasing global.level_reached by one! Below is the code for the end-of-level object that kicks in when the player touches it. Anyone have any ideas what I'm doing wrong?

Code:
instance_create(0,0,obj_fade); //fade the screen
 global.level_reached += 1; //advance counter to transition to the next level
  room_goto(global.level_reached); //now go there!
 

Avram

Member
The only thing I can think of is that I'm going to room numbers, not names. Is that a problem?
 

Filkata

Member
I think using numbers for the rooms can mess up if you have ever deleted or reordered rooms (just a theory, but it can be easily checked in a new project). How about using an enum, you can achieve the same thing but it will be reliable.
 

TheouAegis

Member
Did you actually verify that global.level_reached only went up by one? Or are you just assuming that since your code only raise it by one that it must only go up by one? Did you actually debug the variable to make sure it does in fact only go up by 1 even though you move two rooms? More than likely it actually went up by 2 and you of course then moved to another level.
 

Avram

Member
Thanks for the input, TheouAegis and Fikata. So yes, I realize now that enums would have been a better idea but didn't think of it at the time! TheouAegis, I couldn't figure out why the game was jumping two levels, no matter how many changes I made (I even tried adding 0.5 to the global.level_reached but that didn't help) - what was particularly strange was that you'd briefly see the skipped level before the game transitioned to the following level.

This is the solution I came up with. I don't really know why it works but am willing to accept that it does. The following comes from an object you touch that transports you to the following level:

Code:
instance_create (0,0,obj_fade);
global.level_reached = room; // weird bug - doesn't need the "+ 1"
room_goto (global.level_reached);
instance_destroy();
 
Top