I see room_a(), room_b() etc. in the room script. What is that? How does it work?These are room interaction event functions. The engine calls them when there is some room interaction running. They have the same meaning as global event functions like game_start(), repeatedly_execute(), interface_click() etc.
Room interactions:
Walk off leftoccurs when the player character walks off the left edge of the screen.
Walk off rightoccurs when the player walks off the right edge of the screen.
Walk off bottomoccurs when the player character walks off the bottom edge of the screen.
Walk off topoccurs when the player character walks off the top edge of the screen.
First time enters roomoccurs the first time the player enters the room. This event occurs AFTER the screen has faded in, so it allows you to display a message describing the scene.
Player enters room (before fadein)occurs just after the room is loaded into memory. This event occurs every time the player enters the screen, and it happens BEFORE the screen has faded in, which allows you to change object graphics and do other things to the screen which the player won't notice.
NOTE: This event is ONLY meant for adjusting things such as object and character placement. Do NOT use this event for any sort of automated intro to the room - use the "Enters Room After Fade In" event for that instead.
Repeatedly execute (for this room)occurs repeatedly on every interpreter cycle. The normal game speed is 40 cycles per second, so this event occurs about every 25 milliseconds.
Player enters room (after fadein)occurs every time the player enters the room, AFTER the screen has faded-in. Suitable for displaying text descriptions and so on, that you want the player to see.
Player leaves roomoccurs when the player leaves the screen, just before the screen fades out.
How it works:
When you goto the room interaction editor and add a new interaction then choose RunScript option AGS adds appropriate function for the current room so you could place the code in to decide what you want to be happen when the interaction is running. You may notice the comment line inside of each event function telling what interaction the function is for.
Example:
1. Go to interaction editor
2. Choose interaction: Player enters room (after fadein)
3. Set RunScript option for this interaction
4.
function room_a() {
// script for room: Player enters room (after fadein) player.Animate(...);
player.Walk(100, 200, eBlock);
...
...
etc.
}
So now each time the player has entered the room (after fadein) AGS will animate the player character and move him to the specified co-ordinates.
A Word of warning:You should never place or delete these functions manually. Instead goto the interaction editor and remove appropriate interaction (AGS takes care itself on deleting such functions).
Why is it so? Because when you add new interaction AGS adds an event function as well and
links it with the added interaction.
That means two things:
1. If you open script editor (room) and just place room_*() functions manually AGS will not be able to call them unless the appropriate interaction has been specified first. This is why you can't just copy the whole script code from one room and paste it into the new one. You should create interactions first.
2. If someone posted a script like this:
function room_a() {
cGuy.Walk(...);
...
...
etc.
}
you shouldn't just grab & paste it into the room. Even if you have room_a() function in yours script. The reason it should be avoided is that
the event function name is NOT connected with the interaction equally for all rooms but
depends on on the order the interactions have been added.
What I mean is this:
Interaction editor > Add Interaction > Room: Player enters room (after fadein); RunScript;
Result: function room_
a() has been added.
Interaction editor > Add Interaction > Room: Player enters room (before fadein); RunScript;
Result: function room_
b() has been added.
Interaction editor > Add Interaction > Room: Player leaves screen; RunScript;
Result: function room_
c() has been added.
So in the room script we have:
//room script
function room_
a() {
// script for room: Player enters room (after fadein)}
function room_
b() {
// script for room: Player enters room (before fadein)}
function room_
c() {
// script for room: Player leaves room}
...but changing the order interactions would be added in:
Interaction editor > Add Interaction > Room: Player leaves room; RunScript;
Result: function room_
a() has been added.
Interaction editor > Add Interaction > Room: Player enters room (after fadein); RunScript;
Result: function room_
b() has been added.
Interaction editor > Add Interaction > Room: Player enters room (before fadein); RunScript;
Result: function room_
c() has been added.
... we'll get in the room script:
//room script
function room_
a() {
// script for room: Player leaves room}
function room_
b() {
// script for room: Player enters room (after fadein)}
function room_
c() {
// script for room: Player enters room (before fadein)}
See the difference? The functions have other names.
Btw, there are not only room interactions but hotspot, objects etc. so seeing something like function hospot1_a() {} is also possible.
-
Oops, a bit long post. hope it's not confusing and helps you. If you have any related questions just ask.

-Cheers