GML Persistent object not updating after room_goto()

S

Shizuku

Guest
I have an object marked as persistent that manages transitions between the main menu and gameplay in my fighting game. When the player selects a character and stage, I use room_goto() to change the room to the stage they select and then attempt to create an instance of the character they've chosen.

For now, I'm using this code for testing purposes before I start adding content:
Code:
room_goto(test_fight);
var p1 = instance_create_layer(68, 93, "Players", testP1);
p1.player = 1;
Despite the fact that the room test_fight has a layer called "Players", an error is thrown claiming that the layer does not exist. So then, I try to create a new layer in GML and create the instance on that layer like so:
Code:
room_goto(test_fight);
var newLayer = layer_create(0, "test");
var p1 = instance_create_layer(68, 93, "test", testP1);
p1.player = 1;
When doing this, it doesn't throw errors anymore, but the instance doesn't appear to be created. When I create a layer in the character select room called "Players" and use my original code, no error is thrown and the object does not appear in test_fight. This leads me to believe that the manager object still exists on the character select room, even after executing room_goto(), and it's trying to create the instance there instead of in test_fight.

Why does the manager object not update immediately after using room_goto()? Is there any way to fix this problem, or should I just work around it?
 
S

Shizuku

Guest
Nevermind, I'm an idiot and I didn't read the Documentation close enough. Apparently any events called after room_goto() don't affect the new room until the entire event ends.

This function will end the current room and go to the room specified by the input index. The room must exist or else an error will be given, and if you use the same room as the current room it will have the same effect as room_restart. Note that the room will not change until the end of the event where the function was called, so any code after this has been called will still run.
Moderators, feel free to delete this post since it's answered by the documentation.
 
Top