Code not working pls help

Discussion in 'Programming' started by dannilowdzn, Sep 12, 2019.

  1. dannilowdzn

    dannilowdzn Member

    Joined:
    Sep 12, 2019
    Posts:
    1
    so i created a code to get to another room after giving the right answer, but instead of going to the other room, is restarting the game even if i write the right one

    rightanswer= get_string("What weapon found on the floor was used in the murder?","");
    if(rightanswer="REVOLVER")
    show_message("Right answer");
    if room_exists(room_next(room)) room_goto_next();
    else show_message("Wrong answer");
    room_restart()

    pls helppp, this is for a project that i need to submit today
     
  2. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    977
    First thing is getting your brackets correct. Add brackets around your if then statements, as they are incorrect at the moment.
    Code:
    if this {
      this
    } else {
      that
    }
    
     
  3. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,923
    Also, the code is working, just not the way you intended. This is because room change commands will actually not change the room before current event has ended. So your code calls room_goto_next but still runs until the end, where it encounters room_restart which resets the room. Of the two, latter takes priority and restarts your room.
     
  4. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    111
    what he is saying is else only effects the thing directly below it unless you bracket
    Code:
     rightanswer= get_string("What weapon found on the floor was used in the murder?","");
    if(rightanswer="REVOLVER")
    {
    show_message("Right answer");
    if room_exists(room_next(room)) room_goto_next();
    }
    else
    {
     show_message("Wrong answer");
    room_restart()
    }
    
     

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