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

room_go_to in series

Hi everyone, weird question maybe:

I want to teleport my player to multiple rooms, then go back to the starting room.
The reason is that I want, at a certain moment, have the player teleport to each room,
change that room's instances, go to the next room, change that next room's instances,...
and so on until the list is complete, then go back to the "current room". All of this should
happen during a fade-out screen, which I've already been able to make.

The reason is that I need access to other room's specific instances during this transition. You see, I set a variable to "0". If that one is "0", certain instances will change or even duplicate…. in those other rooms, but only once and then move on to the next room, repeat untill all rooms are done and go back to the starting room.
All in a short time during a 5 second fade-out, fade-in (making it invisible to the player that the player object is actually being teleported all around the game very briefly).
The other rooms are persistent, but the instances in them are not flagged as such, and that should remain that way.

I tried:
room_go_to(room1);
room_go_to(room2);
.
.
.
room_go_to(current room);

If i just go to the first room in the list, and leave out all the others and don't return, obviously i can do exactly what I want with the instances in that room, but then I won't go down the list and return. When making a list like this, it seems to me that the only code that is being run is the final line in the list, basically as if the player is teleported to the current room again while ignoring all others (which has the same effect as room_restart, which is what happens).

I think I don't understand how room_go_to works in this case. I just can't figure it out.
 

jo-thijs

Member
Hi everyone, weird question maybe:

I want to teleport my player to multiple rooms, then go back to the starting room.
The reason is that I want, at a certain moment, have the player teleport to each room,
change that room's instances, go to the next room, change that next room's instances,...
and so on until the list is complete, then go back to the "current room". All of this should
happen during a fade-out screen, which I've already been able to make.

The reason is that I need access to other room's specific instances during this transition. You see, I set a variable to "0". If that one is "0", certain instances will change or even duplicate…. in those other rooms, but only once and then move on to the next room, repeat untill all rooms are done and go back to the starting room.
All in a short time during a 5 second fade-out, fade-in (making it invisible to the player that the player object is actually being teleported all around the game very briefly).
The other rooms are persistent, but the instances in them are not flagged as such, and that should remain that way.

I tried:
room_go_to(room1);
room_go_to(room2);
.
.
.
room_go_to(current room);

If i just go to the first room in the list, and leave out all the others and don't return, obviously i can do exactly what I want with the instances in that room, but then I won't go down the list and return. When making a list like this, it seems to me that the only code that is being run is the final line in the list, basically as if the player is teleported to the current room again while ignoring all others (which has the same effect as room_restart, which is what happens).

I think I don't understand how room_go_to works in this case. I just can't figure it out.
First of all, you're right about the room go to thing.
Using room_goto doesn't immediately change rooms, but sets a flag indicating you requested to change rooms.
Only after all the code has run, the room is changed.

Secondly, it sounds to me like you're approaching this problem in the wrong way.
You want to change things in other persistent rooms.
Don't do that by going to that room, performing the change and immediately heading back to the previous room.
Instead, keep track of the changes you want to make in other rooms and don't apply them until the player actually goes to those rooms through gameplay.
For example:
Create a controller object: objController.
Make this object persistent.
Create an array for this object that keeps track of changes to be made for each room in the create event:
Code:
for(var i = room_last; i >= 0; i--) {
    updates[i] = ds_queue_create();
}
Apply changes in the room start event:
Code:
var queue = updates[room];

while !ds_queue_empty(queue) {
    var update = ds_queue_dequeue(queue);
    var args = ds_queue_dequeue(queue);
    
    script_execute(update, args);
}
Then you can have a script scr_upd_add_instance like this:
Code:
var args = argument0;
var X = args[0];
var Y = args[1];
var layer = args[2];
var obj = args[3];

instance_create_layer(X, Y, layer, obj);
and add an instance in a different room (we'll call it other_room) by:
Code:
var queue = objController.updates[other_room];
ds_queue_enqueue(queue, scr_upd_add_instance, [x, y, "instance_layer", object]);
 
That could work. I'm going to look into that. It's a little annoying that we can't update instances in other rooms across the rest of the game without physically starting the room itself. I wish there was a room_memory function or something, that if set to true, the current room remains loaded in the background and all it's instances run alongside the current room you are in :p
 
Top