Scripting - Operate on Room Load (SOLVED)

Started by Ricardo, Mon 14/11/2005 22:06:49

Previous topic - Next topic

Ricardo

where in the script do I write a command which I want to take place right when the room is loaded?
May The Force be with you

monkey0506

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.

Ricardo

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?
May The Force be with you

Ashen

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.
I know what you're thinking ... Don't think that.

monkey0506

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

Code: ags
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.:

Code: ags
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.

Ricardo

May The Force be with you

SMF spam blocked by CleanTalk