Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tenacious Stu on Tue 20/12/2011 11:18:30

Title: NPC walk, then wait, then walk again between two points
Post by: Tenacious Stu on Tue 20/12/2011 11:18:30
I have this code for an NPC pacing an area. I want it so that when he reaches location 1 or 2, he waits for a few seconds before walking again. I tried to do this using timers, but failed miserably.


function room_RepExec()
{

  if (!cDog.Moving) //only check if the NPC isn't moving
  {
    if (characterLocation==1)
    {
      cDog.Walk(111, 183, eNoBlock, eAnywhere);
      characterLocation=2;
    }
    else
    if (characterLocation==2)
    {
      cDog.Walk(13, 181, eNoBlock, eAnywhere);
      characterLocation=1;
    }
  }
}
Title: Re: NPC walk, then wait, then walk again between two points
Post by: monkey0506 on Tue 20/12/2011 14:17:12
Based on the code you have now, it should be working fine except for the waiting part.

// room script
int dogDelay = 100; // change this to whatever wait duration you want

function room_RepExec()
{
  if (dogDelay) dogDelay--;
  else if (!cDog.Moving)
  {
    if (characterLocation == 1)
    {
      cDog.Walk(111, 183, eNoBlock, eAnywhere);
      characterLocation = 2;
    }
    else if (characterLocation == 2) // unless there's more than 2 locations, this is redundant and could just be 'else'
    {
      cDog.Walk(13, 181, eNoBlock, eAnywhere);
      characterLocation = 1;
    }
    dogDelay = 100; // again, change this as appropriate
  }
}