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

SOLVED Problem with Room Order in GMS 2.3

A

AF_2004

Guest
So I've encountered a pretty major problem, which is really stopping me from being able to work on my game further. I've seen other people post about this issue as well back when the 2.3 update came out, but I haven't come across a solution that works for me. Basically, whenever I add a new room now, it seems like I am unable to change its room order. Even when I do it through the room manager, it doesn't seem to make a difference. Now my problem isn't going from room to room, because I use room_goto(), however it does mess up one of the things I do at the beginning of the game. Basically, I have a display manager object which cycles through all the rooms at the beginning of the game and changes the view of all the rooms until it reaches the final room. The problem is that for some reason, the new room I have added is not being affected. Maybe I'm misunderstanding the problem and that this isn't really an issue with the room order, but that is all I can think of that could be causing this. Is there any way to fix this issue? Here is the code that I use(btw I got this code from pixelated pope's video about aspect ratios I think):
GML:
for (var i = 1; i <= room_last; i++;) {
    if room_exists(i) {
        room_set_view(i, 0, true, 0, 0, ideal_width, ideal_height, 0, 0, ideal_width, ideal_height, 0, 0, 0, 0, -1);
        room_set_view_enabled(i, true);
    }
}
 

Roldy

Member
Think about it.
  • What is the value of room_last?
  • In the context of room indices, what does '1' refer to?
  • How does '1' relate to room_last?

Don't set 'i = 1.' set it to room_first;
Don't 'i++'. Use room_next.

e.g.

GML:
var i = room_first;

while(room_exist(i)) {

    // Do stuff to room 'i'

    i = room_next(i);
}
In the above code 'i' consistently refers to a the room index; which is assigned by order of creation (undocumented) not room order.
In your code 'i' is all mixed up.

room_first
room_next
room_exists
 
Last edited:
A

AF_2004

Guest
Think about it.
  • What is the value of room_last?
  • In the context of room indices, what does '1' refer to?
  • How does '1' relate to room_last?

Don't set 'i = 1.' set it to room_first;
Don't 'i++'. Use room_next.

e.g.

GML:
var i = room_first;

while(room_exist(i)) {

    // Do stuff to room 'i'

    i = room_next(i);
}
In the above code 'i' consistently refers to a the room index; which is assigned by order of creation (undocumented) not room order.
In your code 'i' is all mixed up.

room_first
room_next
room_exists
Wow, I can't believe I never thought of it that way. It was never a problem before 2.3, or even back in 1.4. Thank you so much! :D
 

LtCoyote

Member
Yep, Roldy's method is better. I just run into the same problem. It could be caused of the fact that my project is imported to 2.3 from the version before, like a month or two prior today, so my room order is a mess (level_06 was not the first room I've created for sure). Though fact of the matter is the room_last equals a room BEFORE the actual last room, meaning, I can only access the actual last room with room_last+1 which is madness of course. Also interesting that I haven't noticed it for weeks as it worked in the past and after upgradeing to 2.3, and today, like magic, it was just not working, one of my screens was scaled to the room's proportions.
Anyways, Roldy is a savior, a hero, a legend. This method works nicely. :)
 

gnysek

Member
Let's say, you have 3 rooms:
- room0, room1, room2

What ids those rooms have?
- in GameMaker 1-8, GameMaker Studio 1.x and GameMaker Studio 2.0-2.2.x, their ids will be in order, 0, 1, 2
- in GameMakerStudio 2.3+, their order can be random (you can preview their real order in .yyg file, but it might change at later time!)

So, let's say, that you ordered rooms in this order:
- [Start] room1, room0, room2

What value lies under room_last? In GMS < 2.3, it would be 2. In GMS 2.3+ it can be any of 3 values, 0, 1, 2 and it can change between runs, if you reorder any resources in tree. Only think that's for sure, is that room_las == room2 in that case, but we don't know room2 value until game runs.

So, safest method to update everything would be:
GML:
var r = 0;
while(room_exists(r)) {
   // change room properties here
   r++;
}
Don't rely on using room_first and room_last in any loop in GMS 2.3+! Don't rely on pre-2.3 undocumented feature, that first resource in tree have id=0, and last have id equal to number of this type of resources-1. This is not true anymore.
 

chamaeleon

Member
I assume you can rely on room_first and room_last if you use room_next() and room_prev() to iterate in your loop, with the understanding the two variables and the two functions uses the order in the room manager (with the caveat that room_next() and room_prev() does not take dynamically added rooms into account per their documentation).
GML:
var rm = room_first;
do {
   ...
   rm = room_next(rm);
} until (rm == -1);
Edit: Clearly I shouldn't have look at only the last reply, as Roldy already covered this.
 
Last edited:
Top