Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: johnny1finger on Fri 29/06/2012 17:02:25

Title: SOLVED: Issues with moving multiple NPCs simultaneously
Post by: johnny1finger on Fri 29/06/2012 17:02:25
I'm needing to have 3 characters (or objects) walk/move on the screen at the same time.  I say either, because it doesn't matter to me which they are for this scene.  I have tried tackling it with timers, regions, hotspots, however nothing yields a successful result.  I've tried numerous blocking style arrangements, but I either get 1 moving and the other 2 not moving or I get all 3 moving to one location, then nothing.

For the scene, I have 3 characters/objects that each have their own separate 2 locations (walking points).  I need each to walk continuously back and forth between point A & B.

I think I'm on the right track with this code, but I seem to be missing something.  This is for one of the 3 (cAerialGirl1), which I'm assuming if I get it working, I can replicate it across the other 2 characters (cAerialGirl2 & 3).

Code (AGS) Select

function room_RepExec()
{
  int characterLocation;
  if (!cAerialGirl1.Moving) //only check if the NPC isn't moving
  {
    if (characterLocation==1)
    {
      cAerialGirl1.Walk(203, 149, eNoBlock, eAnywhere);
      characterLocation=2;
    }
    else
    if (characterLocation==2)
    {
      cAerialGirl1.Walk(204, 136, eNoBlock, eAnywhere);
      characterLocation=1;
    }
  }
}


Again, I apologize if it's something simple.  Integers are not my strong suit yet and I'm learning as I go.  I've searched high and low in the manual, wiki and forums and the search has turned up nothing.  I may not be using the correct search criteria, but in any case, I'm stumped.  Thanks in advance for the help....AGAIN!!  :P
-j
Title: Re: Issues with moving multiple NPCs simultaneously
Post by: Khris on Fri 29/06/2012 17:07:49
The Problem is that the .Moving property's value lags behind for one frame.
What happens is that the commands are all executed, but the character never gets to start their walk.

Try this:
Code (ags) Select
    if (cAerialGirl1.y == 136) cAerialGirl1.Walk(203, 149, eNoBlock, eAnywhere);
    else if (cAerialGirl1.y == 149) cAerialGirl1.Walk(204, 136, eNoBlock, eAnywhere);
Title: Re: Issues with moving multiple NPCs simultaneously
Post by: johnny1finger on Fri 29/06/2012 17:32:56
Thanks Khris for the quick reply.  I can't seem to make your code work.  The character does nothing.  I've tried starting cAerialGirl1 at 204, 136..that did not work and I've also tried adding
Code (AGS) Select

cAerialGirl1.Walk(204,136, eNoBlock, eAnyWhere);

to the room_Load() event, which makes it walk to the coords, however when it gets there, it stops.

I totally removed what I had and added your code to the repeatedly_execute event.  Did I do something wrong? Also, there is nothing else going on in the room.  This is the only code.
Thanks again,
-j
EDIT:  also, the whole screen is a walkable area....
Title: Re: Issues with moving multiple NPCs simultaneously
Post by: Khris on Fri 29/06/2012 18:15:25
My code was meant to replace the lines inside the !Moving check.
I've just realized that it probably won't work either because again, the .Move command is called each loop.

Here's the full code that should work:
Code (ags) Select
int delay;

function room_RepExec()
{
  if (!cAerialGirl1.Moving && delay) //only check if the NPC isn't moving
  {
    if (cAerialGirl1.y == 136) cAerialGirl1.Walk(203, 149, eNoBlock, eAnywhere);
    else if (cAerialGirl1.y == 149) cAerialGirl1.Walk(204, 136, eNoBlock, eAnywhere);
    delay = 0;
  }
  else if (!delay) delay = 1;
}
Title: Re: Issues with moving multiple NPCs simultaneously
Post by: johnny1finger on Fri 29/06/2012 18:19:37
I'm sure I *should* have known that!!  At least now I understand the complete code that I'm using.  Believe it or not, it is getting easier  :P

Thanks Khris!  Works like a charm!!
-j