Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ricardo on Mon 14/11/2005 22:06:49

Title: Scripting - Operate on Room Load (SOLVED)
Post by: Ricardo on Mon 14/11/2005 22:06:49
where in the script do I write a command which I want to take place right when the room is loaded?
Title: Re: Scripting - Operater on Room Load
Post by: monkey0506 on Mon 14/11/2005 22:12:36
Look up the function on_event in the help manual.  There is an event titled "eEventEnterRoomBeforeFadein" that you can use to determine when the user has entered a new room, and the data parameter of the function will contain the room number.  There is also the Interaction Editor which has events for "Player enters room (before fadein)" and "Player enters room (after fadein)", where you can script the interaction.
Title: Re: Scripting - Operater on Room Load
Post by: Ricardo on Mon 14/11/2005 22:25:48
If I understand correctly this function works for all the rooms in general, but what do I do if I only want it to work when I go into a specific room?
Title: Re: Scripting - Operater on Room Load
Post by: Ashen on Mon 14/11/2005 22:36:54
The on_event function will work for all rooms (although you can make it for a specific room if you want, as monkey_05_06 said, with the data parameter).

The Player enters room - before/after fade-in Interaction events are always room specific.
Title: Re: Scripting - Operater on Room Load
Post by: monkey0506 on Mon 14/11/2005 22:39:09
For the on_event function:

function on_event(EventType event, int data)

EVENT is eEventEnterRoomBeforeFadein.

DATA is the room number.

So you can use DATA to check which room it is that is being entered, i.e.:

function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    if (data == 5) {
      // run interaction for player enters room 5
      }
    }
  }


And the Interaction Editor is developed on a room-to-room basis.  So if you open the Interaction Editor and under the "Player enters room (before fadein)" event you put a "Run Script" action, then went to a different room, the event wouldn't be on that room's list of interactions.

So you can use the DATA parameter of the on_event function or just use the Interaction Editor.  Either way you can set it up on a room-to-room basis.

In the event that you did want to do something EVERY time the player entered a room, such as making sure that he was on a walkable area, then you could just use the on_event function, and omit the check of the DATA parameter, i.e.:

function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    player.PlaceOnWalkableArea();
    }
  }


I hope that this helps.

Ashen posted before me, but I'll post this anyway just to try and help clarify his post.
Title: Re: Scripting - Operate on Room Load
Post by: Ricardo on Mon 14/11/2005 22:39:26
Thanks... solved