1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Room Transition Problems

Discussion in 'Programming' started by Avram, Feb 21, 2019.

  1. Avram

    Avram Member

    Joined:
    Jun 21, 2016
    Posts:
    46
    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!
     
  2. Avram

    Avram Member

    Joined:
    Jun 21, 2016
    Posts:
    46
    The only thing I can think of is that I'm going to room numbers, not names. Is that a problem?
     
  3. Filkata

    Filkata Member

    Joined:
    Jan 8, 2019
    Posts:
    13
    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.
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,143
    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.
     
  5. Avram

    Avram Member

    Joined:
    Jun 21, 2016
    Posts:
    46
    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(); 
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice