That's the right approach, but it can be done with even less code.
I assume your game uses rooms that are positioned on a uniform grid, right? Like the first few King's Quest and Quest for Glory games?
// add to global script
#define border 10
bool map_room_change;
void NextRoom() {
if (player.x < border) player.ChangeRoom(GetRoomProperty("west"));
if (player.x > Room.Width - border) player.ChangeRoom(GetRoomProperty("east"));
if (player.y < border) player.ChangeRoom(GetRoomProperty("north"));
if (player.y > Room.Height - border) player.ChangeRoom(GetRoomProperty("south"));
map_room_change = true;
}
void on_event(EventType event, int data) {
if (event == eEventEnterRoomBeforeFadein) {
if (!map_room_change) return; // exit here if intro / menu / other room
int pr = player.PreviousRoom;
if (pr == GetRoomProperty("west")) player.x = border+2;
if (pr == GetRoomProperty("east")) player.x = Room.Width - (border+2);
if (pr == GetRoomProperty("north")) player.y = border+2;
if (pr == GetRoomProperty("south")) player.y = Room.Height - (border+2);
map_room_change = false;
}
}
As you can see in the second function, the player is positioned
after they've arrived in the new room, so the game can easily place them at the edge, even if the room is wider or higher than others.
Now add custom properties to the rooms.
-Open any room, and in the properties, click Properties, then the [...] button.
-in the window that opens, click "Edit schema..."
-right click inside the new window and select "Add new property..."
-Name: north, Description: room to the north (or whatever, not needed), Type: Number, Default Value: -1, Applies to: check only "Rooms"
-Repeat for the other three directions, then close the schema editor.
Now you can conveniently set all the room connections in here, without going into/adding several functions for each room.
To trigger the room change, I'd use a single region. Draw a rectangle at each edge of the room, using one color. Make sure it is narrower than the value of
border. In its "player walks on region" event field, simply write "NextRoom", without quotes.
For special cases, like for instance when the player goes south from a 400 pixels wide room into a 320 pixels wide room, just use a second region and put the code in manually:
player.ChangeRoom(17, (player.x*320)/400, 12);