Switch Statement running twice

Squin

Member
GML:
switch(menu_index) {
    case 0: room_goto(EN);
            room_instance_add(EN, 80,63,obj_char);
            room_instance_add(EN, 0, 0, Obj_pause);
            room_instance_add(EN, 0, 0, obj_clock);
        break;
    case 1: game_end();
        break;
}
So with this code the main menu draws these objects in the next room and it works fine the first time, but when you pause and go back to the main menu and then start the game again it makes 2 of each the second time and so on. The pause menu deletes the objects when you go back to main menu btw.
Anyone know why it'd be doing this?
 

baconlovar

Member
It’s kinda hard to tell from my end but it is possible the objects aren’t actually being removed when going back to the main menu. Is the room you are going to persistent? OR maybe it could be that you are adding instances after room_goto

also is it supposed to be obj_pause not 0bj_pause on line 4

like I said it’s hard but I hope this helps at least a little
 

Squin

Member
The room isn't persistent, but I just made it so the room itself spawns the objects instead of the previous rooms menu and that seems to be working. Thank you :)
 
Anyone know why it'd be doing this?
From the manual on room_instance_add()
Note that calling this function on a room asset created in the Asset Browser will permanently add the instance to the room, and even calling game_restart() will not return the room to it's original state (only ending the game and opening it again will start with the room in its original state again).
So would appear to be working as intended as this function is a way to add instances permanently to the room while the game is running.

The room isn't persistent, but I just made it so the room itself spawns the objects instead of the previous rooms menu and that seems to be working.
Glad you figured out a different way to do it.
 
Top