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

Question - Code [SOLVED] 'room_goto' never displays new room

M

mdbussen

Guest
I am trying to instantiate a new room via GML and then enter the new room. This appears to work (in the sense that I can see my code is moving past the 'room_goto' function call) but I never see the display change to reflect the fact that I am in a new room. Here is my code:

Code:
// create a new room and set up the width/height and background color
var room_handle = room_add();
room_set_width(room_handle, DISPLAY_WIDTH_PIXELS);
room_set_height(room_handle, DISPLAY_HEIGHT_PIXELS);
room_set_background_color(room_handle, c_blue, true);
room_set_viewport(room_handle, 0, true, 0, 0, DISPLAY_WIDTH_PIXELS * 2, DISPLAY_HEIGHT_PIXELS * 2);

// jump to the new room
room_goto(room_handle);

// instantiate a 'world_creation' object to keep the user updated on what is happening during world creation
var object_handle = instance_create_depth(0, 0, 0, obj_world_creation_tracker);
ds_map_add(global.object_map, obj_world_creation_tracker, object_handle);
I have some buttons on my "current" room (the one i am in before the "room_goto" call) that never disappear even though the code moves well past this "room_goto" call. I also never see anything related to the 'obj_world_creation_tracker' object, which has several things defined in its draw event that I should be seeing on the screen.

The GMS2 documentation has the following text pertaining to the "room_goto" function:

Note that calling this function does not instantly change rooms, and the room will not change until the end of the current game frame (meaning that any code after this function will still be run, as will some events).
I am not quite sure what to make of this. does this mean that the code I have right after 'room_goto' is not guaranteed to be called in the new room? Is this comment related to the problems I am having or not?
 

Stubbjax

Member
I am not quite sure what to make of this. does this mean that the code I have right after 'room_goto' is not guaranteed to be called in the new room? Is this comment related to the problems I am having or not?
You cannot switch rooms in the middle of the game loop. This means all current scripts and events will finish before the room transitions. So the few lines after your "room_goto" line will run in your current room before the game changes to the new room.
 
M

mdbussen

Guest
You cannot switch rooms in the middle of the game loop. This means all current scripts and events will finish before the room transitions. So the few lines after your "room_goto" line will run in your current room before the game changes to the new room.
Thanks!

Updated code below. I now call 'room_instance_add' prior to the 'room_goto'

Code:
// create a new room and set up the width/height and background color
var room_handle = room_add();
room_set_width(room_handle, DISPLAY_WIDTH_PIXELS);
room_set_height(room_handle, DISPLAY_HEIGHT_PIXELS);
room_set_background_color(room_handle, c_blue, true);
room_set_viewport(room_handle, 0, true, 0, 0, DISPLAY_WIDTH_PIXELS * 2, DISPLAY_HEIGHT_PIXELS * 2);

// instantiate a 'world_creation' object to keep the user updated on what is happening during world creation
var object_handle = room_instance_add(room_handle, 0, 0, obj_world_creation_tracker);
ds_map_add(global.object_map, obj_world_creation_tracker, object_handle);

// jump to the new room
room_goto(room_handle);
 
Top