• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Help with a code

DreTazzz

Member
Hi there,

If someone one please explain why my codes arent working? They are:


Under a Step Event within a TimeLine.

if room_exists(room_secretRoom_Dre) || room_exists(room_secretRoom_Tommy)
{
room_goto(room_midStartFromSecretBattle);
}
else
{
room_goto(room_arcadeGameOptions);
}


It keeps only going to the midStart room. Also, I have similar code that i am trying to do to adjust a variable:


CREATE EVENT under the obj_Enemy

if room_exists(room_secretRoom_Tommy)
{
enemyHp = 20;
}

if room_exists(room_bombsAway)
{
enemyHp = 100;
}

With this one, the Hp is always 20 in either room.
Any help would be great. Thank you. :cool:
André
 

chamaeleon

Member
Hi there,

If someone one please explain why my codes arent working? They are:


Under a Step Event within a TimeLine.

if room_exists(room_secretRoom_Dre) || room_exists(room_secretRoom_Tommy)
{
room_goto(room_midStartFromSecretBattle);
}
else
{
room_goto(room_arcadeGameOptions);
}


It keeps only going to the midStart room. Also, I have similar code that i am trying to do to adjust a variable:


CREATE EVENT under the obj_Enemy

if room_exists(room_secretRoom_Tommy)
{
enemyHp = 20;
}

if room_exists(room_bombsAway)
{
enemyHp = 100;
}

With this one, the Hp is always 20 in either room.
Any help would be great. Thank you. :cool:
André
If these rooms are rooms you have created in GMS as resources, rather than potentially added using room_add() (so that there's a potential for the function to return false if you haven't added some given room), all room_exists() calls will return true regardless of what room you are in. Seems to me that what you probably want to do is compare the room variable with room_secretRoom_Dre, etc., instead.
GML:
if (room == room_secretRoom_Dre) || (room == room_secretRoom_Tommy)
{
     room_goto(room_midStartFromSecretBattle);
}
else
{
     room_goto(room_arcadeGameOptions);
}
 

DreTazzz

Member
If these rooms are rooms you have created in GMS as resources, rather than potentially added using room_add() (so that there's a potential for the function to return false if you haven't added some given room), all room_exists() calls will return true regardless of what room you are in. Seems to me that what you probably want to do is compare the room variable with room_secretRoom_Dre, etc., instead.
GML:
if (room == room_secretRoom_Dre) || (room == room_secretRoom_Tommy)
{
     room_goto(room_midStartFromSecretBattle);
}
else
{
     room_goto(room_arcadeGameOptions);
}

Your code WORKED! Thanks so much, Chamaeleon.
 
Top