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

GMS 2 Why Does this not work?

Discussion in 'Programming' started by Alexthom, Dec 3, 2019.

  1. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    12
    I just want to have a program where it simply starts at a title, then lets the player look down to the options, and look back up.There's two rooms.
    Here's the programming:

    if(keyboard_check_pressed(vk_down)){
    room_goto_next()
    }
    if(keyboard_check_pressed(vk_up)){
    room_goto_previous()
    }

    When I run it, I can go down, but then not back up.

    And yes, I am aware that there will be an error when pressing up on the first room. I know how to fix that already.
     
  2. BattleRifle BR55

    BattleRifle BR55 Member

    Joined:
    Jun 24, 2016
    Posts:
    996
    Does this instance exist in the second room?
     
  3. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    12
    So I’m a beginner so don’t judge me if this is kinda a newbie thing to say-how do you program a separate room?
     
  4. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,121
    You don't really program a room, so much as add it (which it seems like you've already figured out).

    The important things to know is that when you switch rooms, through whatever method, all non persistent objects are destroyed. So, if the object with that code is in the first room, but is not persistent, then when you switch to the second room, it is destroyed. There are two solutions to this. First, make the object persistent. You do this in the object window that opens up when double clicking an object in the resource window. Second, add it to the second room as well.

    There isn't a right answer as to which one to use. Which one you choose (new object or single persistent object) is up to you and somewhat dependent on code. If that is all the code there is, either method would work fine.
     
  5. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    12
    Thanks!
     

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