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

Code not working pls help

D

dannilowdzn

Guest
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
 

Slyddar

Member
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
}
 

NightFrost

Member
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.
 
S

spoonsinbunnies

Guest
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.
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()
}
 
Top