GML room_goto DOESN'T WORK HELP ME PLEASEEEEEEE

I have an object (button), which in the Left Mouse Button event has a code to restart the room (change player's x & y to the start, room_restart, etc.). But, that works only if you're restarting in a solid level (no other rooms). In other cases, however, that doesn't work. I've added room_goto to the code, and it won't work!!!
GML:
if (room = Tutorial02)
{
    instance_activate_all();
    room_goto(Tutorial01);
    oChar.x = 156;
    oChar.y = 650;
}
Everything in this code works, except the room_goto. I've tried many things and none of them work. My character keeps spawning at written coordinates, but in the wrong room! Any ideas?
Please help, i've been struggling for half a hour.
P.S.
it also doesn't restart the level somewhy, althrough the upper code for the first level does that
 
Last edited:
Ok...Firstly, instance_activate_all() is doing nothing if you are changing rooms in the next line of code. There's no reason to activate anything as it will all be destroyed when the room changes (unless you have a persistent object, in which case, why instance_activate_all()?), secondly, setting oChar.x and oChar.y after room_goto() also does nothing as it will only move oChar in the current room. I think you need to rethink how your code is structured.
 
Ok...Firstly, instance_activate_all() is doing nothing if you are changing rooms in the next line of code. There's no reason to activate anything as it will all be destroyed when the room changes (unless you have a persistent object, in which case, why instance_activate_all()?), secondly, setting oChar.x and oChar.y after room_goto() also does nothing as it will only move oChar in the current room. I think you need to rethink how your code is structured.
instance_activate_all meant to activate the objects after pausing, without it room spawns empty
 

Spam1985

Member
try this and see if the message shows:
GML:
if (room = Tutorial02)
{
    show_message("I like potatoes");
    instance_activate_all();
    room_goto(Tutorial01);
    oChar.x = 156;
    oChar.y = 650;
}
 

FoxyOfJungle

Kazan Games
For some reason you are in room 1, and when you go to room 2, do you go back to room 1 again? (Since you are checking if you are in room 2). So this is obviously going to look like it doesn't work.

You also need to make sure you are not in a "collision loop"...

I also suggest you put your code in order. The code is executed from top to bottom.
 
Top