Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KodiakBehr on Tue 03/12/2013 03:42:49

Title: Walking when not in a room.
Post by: KodiakBehr on Tue 03/12/2013 03:42:49
To your knowledge, is there any way to make a non-player character walk in a room that the player character is not in.

I want the first player character to start to walk to a location, the player to be able to switch by button to a second player character in an unrelated room, and have the first player character continue walking uninterrupted to a point, and then transfer rooms, out of sight.  Is this even possible?
Title: Re: Walking when not in a room.
Post by: Ghost on Tue 03/12/2013 04:56:55
You want the character to walk "outside of the room boundaries", yes? That's possible.

For example Character.Walk(-60, 120, eBlocking, eAnywhere) will make a character walk outside of a room to the left. The important bit is the eAnywhere parameter, which makes the walk command ignore walkable areas.
The you can simply move the character to a new room with the ChangeRoom command: He'll "teleport" offscreen then.

Title: Re: Walking when not in a room.
Post by: Secret Fawful on Tue 03/12/2013 05:11:26
If you're talking about a character not stopping when you switch to a character in another room, but continuing to walk so that if you switch back he's still doing what you're wanting him to do, I don't know how possible that is, because I haven't tested it-- but the first place I would look is the Character Control module. This lets you set non-blocking paths for a character to walk whether you're in the room or not.
Title: Re: Walking when not in a room.
Post by: KodiakBehr on Tue 03/12/2013 13:21:36
Quote from: Ghost on Tue 03/12/2013 04:56:55
You want the character to walk "outside of the room boundaries", yes? That's possible.

Nope.  I want things to happen in other rooms.

Quote from: Secret Fawful on Tue 03/12/2013 05:11:26
If you're talking about a character not stopping when you switch to a character in another room, but continuing to walk so that if you switch back he's still doing what you're wanting him to do, I don't know how possible that is, because I haven't tested it-- but the first place I would look is the Character Control module. This lets you set non-blocking paths for a character to walk whether you're in the room or not.

I'll take a look at this module and see if it's of any utility.
Title: Re: Walking when not in a room.
Post by: Khris on Tue 03/12/2013 13:29:00
The thing here is that unless you want the character to trigger region events or do AI-stuff or anything like that, you don't have to simulate them actually walking.
If they eventually transfer rooms, why not simply move the character right to the spot where the player will see them the next time?

I don't think it's possible to call .Walk on characters not in the current room (because it kind of is pointless). The only possible workarounds I can see is either set them to transparent and have them walk in the current room (using eAnywhere) or instead of using several AGS-Rooms, use one big one containing multiple game-rooms.

Could you elaborate on what you're trying to show in the game? Because I don't think you even need this, unless I'm missing something.
Title: Re: Walking when not in a room.
Post by: selmiak on Tue 03/12/2013 16:31:42
I'd store every walkto coordinates in for every character in global character1x and character1y variables and when reentering the room check against the stored global values for that character (and if character is in room) and position them correctly in room load.
Title: Re: Walking when not in a room.
Post by: KodiakBehr on Tue 03/12/2013 19:13:09
Quote from: Khris on Tue 03/12/2013 13:29:00
Could you elaborate on what you're trying to show in the game? Because I don't think you even need this, unless I'm missing something.

I've redesigned the concept slightly so that instead of a number of smaller rooms, there is one gigantic room with multiple NPCs inside.

Conceptually, what I'm looking to accomplish is to have the player give a command to an NPC character by pressing a GUI button and have that character walk to a location and perform a specific action or animation or something, all without blocking.  With more buttons, a player could then give three orders to three NPC characters and watch all three characters walk to different parts of the giant room and carry out their instructions simultaneously.

It's the without blocking part that is tripping me up a little bit.  Could I not just click a button, have an NPC follow a path around the room until it steps onto a region that, when stepped on, triggers an action animation for that NPC (in the room, but off the screen) so that the NPC could be seen "doing" what was commanded?
Title: Re: Walking when not in a room.
Post by: Khris on Tue 03/12/2013 22:58:12
I'm even more confused now than before.

When did you redesign the concept? Just now? Or before you started the topic?
And how would you be able to see something that happens off the screen...?
Are the NPCs in the same AGS-room or not?

Assuming they are, just send them on their way with .Walk(x, y), which is non-blocking, then check their coordinates with Region.GetAtRoomXY in rep_ex_always.
Title: Re: Walking when not in a room.
Post by: KodiakBehr on Tue 03/12/2013 23:07:19
Apologies for the confusion, between my second and third posts, I realized that there's no real need for separate rooms for what I'm attempting, so started working this with one giant room.

I've run a few tests and am starting the get the effects I want.  Thanks for the help, guys!
Title: Re: Walking when not in a room.
Post by: KodiakBehr on Wed 04/12/2013 04:02:40
Just to follow up, and to solicit for ideas on something that's had me stumped for the past few hours...

I'm using the following rep_exec code in the room.

Code (ags) Select

function room_RepExec() {
 
  if (Region.GetAtRoomXY(character[a].x, character[a].y) == region[1]){
    character[a].Animate(8, 0, eRepeat, eNoBlock, eForwards);
    Display("Ding.");
  }
 
   a++;
   if (a>2)a=0; 


With this, as it's written, an NPC can be commanded to walk to a point and perform an animation, but can never escape from that because the rep_exec will overrule any other commands.

If I add a line telling the region to deactivate itself upon arrival, I have no way to reactivate the region upon the NPC being commanded to step off the region (at least, without creating a second region).

Is there a better way to have the animation and ding happen once only, the second the NPC steps onto the region?  But also happen again if the NPC steps off the region, and back onto it?

Thanks again.
Title: Re: Walking when not in a room.
Post by: Khris on Wed 04/12/2013 05:05:39
Try this:

Code (ags) Select
int old_region[3];

function room_RepExec() {

  int cid = 0;
  while (cid < 3) {
    Region *r = Region.GetAtRoomXY(character[cid].x, character[cid].y);
    int new_region = r.ID;
    if (new_region != old_region[cid]) {
      if (new_region == 1) {
        character[cid].Animate(8, 0, eRepeat, eNoBlock, eForwards);
        Display("Ding");
      }
    }
    old_region[cid] = new_region;
    cid++;
  }
}
Title: Re: Walking when not in a room.
Post by: KodiakBehr on Wed 04/12/2013 05:12:36
I would never have come up with this elegant solution.  Thank you again, Khris!