Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: sloppy on Fri 16/12/2005 23:18:40

Title: Entering a room from different places
Post by: sloppy on Fri 16/12/2005 23:18:40
Is it possible to script it so that I can enter a room from other rooms but have different actions happen when coming from each?
Title: Re: Entering a room from different places
Post by: monkey0506 on Sat 17/12/2005 03:45:10
Maybe using on_event and Character.PreviousRoom.  I'm not sure what version of AGS you're using, but if it's 2.62 or earlier then you would replace "Character.PreviousRoom" with "character[].prevroom".  Look them up in the manual and you should be able to figure it out (I'd look it up, but...).  The basic idea would be something along the lines of:

// global script - 2.7+ CODE
function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadeIn) {
    if (data == 5) { // where 5 is the NEW room number
      if (player.PreviousRoom == 4) {
        /* do stuff when entering room 5 from room 4 */
        }
      else if (player.PreviousRoom == 6) {
        /* do stuff when entering room 5 from room 6 */
        }
      }
    }
  }


// global script - 2.62- CODE
function on_event(int event, int data) {
  if (event == ENTER_ROOM) {
    if (data == 5) { // where 5 is the NEW room number
      if (character[GetPlayerCharacter()].prevroom == 4) {
        /* do stuff when entering room 5 from room 4 */
        }
      else if (character[GetPlayerCharacter()].prevroom == 6) {
        /* do stuff when entering room 5 from room 6 */
        }
      }
    }
  }


This code is untested, but that should give you a basic idea.
Title: Re: Entering a room from different places
Post by: Ashen on Sat 17/12/2005 12:40:22
Character.PreviousRoom is definately what's needed, but why use on_event? Put the code in one of the Player enters screen interactions of the new room - this'll make it easier to keep track of what code goes with what room (compared to a load of if(data == X) conditions), and allows you to do stuff AFTER fade in (e.g. move characters, run blocking commands).
Title: Re: Entering a room from different places
Post by: monkey0506 on Sat 17/12/2005 15:33:28
Well...I like to do things from the script...I know you could still use Run Script but I just don't like the interaction editor. :P
Title: Re: Entering a room from different places
Post by: RocketGirl on Mon 19/12/2005 04:41:15
Hmmm...what sorts of things will the character be doing when coming from one room or another?
Title: Re: Entering a room from different places
Post by: sloppy on Tue 20/12/2005 01:28:05
I was going to answer your question, but I guess you're joking right?
Title: Re: Entering a room from different places
Post by: RocketGirl on Tue 20/12/2005 01:37:59
Quote from: sloppy on Tue 20/12/2005 01:28:05
I was going to answer your question, but I guess you're joking right?

Assuming you mean me...well, no, actually.

See, I was thinking about how to make a room with multiple exits and thus, by extension, multiple entrances as well. Being that AGS only gives us four "walls" with which to define the boundaries of a room, having, say, a northwest and a southwest exit could produce some problems, so one would have to use hotspots to trigger the room change, right? Well, suppose one of those exits was a door and we wanted it to close behind the player if they entered from that hallway, for example.
But what if, instead, those exits both led to the same room, but a different part of it. Two parallel bridges leading across a chasm, for example. Suddenly it's not the room that matters so much as how the player exits one and enters the other. But if you want something different to happen based on the entrance one uses, well...it could make a difference.

Of course, if all you want is to have something happen based on the four cardinal directions one could enter from, well, that simplifies things, yes, but it also completely changes how one might operate.

So, no, I was seriously curious what you were trying to accomplish.
Title: Re: Entering a room from different places
Post by: Ashen on Tue 20/12/2005 02:09:10
I'm curious too, but unless there's a technical question in there, this isn't really the place to be asking. If you do have a technical question, feel free to ask it here, rather than starting a new thread.

sloppy, if you're going to reply, take it to PM, please.
Title: Re: Entering a room from different places
Post by: monkey0506 on Tue 20/12/2005 18:13:13
On a techical note, it would be better to use regions than hotspots for leaving a room.  And it wouldn't really be difficult to manage, you just place the region, click Interaction, then define what should happen, i.e. the character should go to a new room (under the player walks onto region event).  That way you could easily manage several exits, and you could just set the room-coordinates in the new room command to make them enter a single room from different points.