Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Wogoat on Thu 10/01/2013 03:37:40

Title: Waiting for a character to finish an action without blocking
Post by: Wogoat on Thu 10/01/2013 03:37:40
I'm working on a game with a fairly standard distraction puzzle.  Character walks away, and eventually comes back.

When the character comes back, I have it so she walks to her spot, says something, then animates sitting down.
I'd like to have her do this in order without the movement and animation using eBlock so the game doesn't pause when she moves.

However if I do, she starts walking, immediately says her line and animates sitting, all while still walking to her spot.
I'm sure there's something simple I'm missing but I've completely overlooked it.  Any suggestions for how to handle this?
Title: Re: Waiting for a character to finish an action without blocking
Post by: Khris on Thu 10/01/2013 08:57:45
You could use a timer:
Code (ags) Select
  cWoman.Walk(123, 123);
  SetTimer(1, 100); // 2.5 seconds

// in Room's RepExec
  if (IsTimerExpired(1)) {
    cWoman.Say();
    // animation


An alternative without a timer:
Code (ags) Select
  cWoman.Walk(123, 123);
  walking_to_chair = true;  // room variable, bool

// in Room's RepExec
  if (walking_to_chair && !cWoman.Moving) {
    walking_to_chair = false;
    cWoman.Say();
    // animation


There might be a slight problem with the second method because iirc, Character.Moving is only set to true at the next game loop and so the condition might be true immediately. To compensate, you can add a coordinates check like && cWoman.x > 120 to the condition.