Entering a room from different places

Started by sloppy, Fri 16/12/2005 23:18:40

Previous topic - Next topic

sloppy

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?

monkey0506

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:

Code: ags
// 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 */
        }
      }
    }
  }


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

Ashen

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

monkey0506

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

RocketGirl

Hmmm...what sorts of things will the character be doing when coming from one room or another?
May the Force be with you

sloppy

I was going to answer your question, but I guess you're joking right?

RocketGirl

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.
May the Force be with you

Ashen

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

monkey0506

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.

SMF spam blocked by CleanTalk