Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: PERXEO on Mon 22/05/2023 20:28:19

Title: Start a timer if the player does nothing (SOLVED)
Post by: PERXEO on Mon 22/05/2023 20:28:19
I'd like to make a timer so that only when the player is standing still for a series of cycles, it could trigger a nice action like saying something, or scratching or looking at the clock. Something like
if(!player.Moving)
  {
     SetTimer(1,10000);
     if (IsTimerExpired(1))
     {
       player.Say("I'm getting bored");
        ,,,,any other action....
     }
  }

but I don't know where to place it and how to make it work correctly...
Title: Re: Start a timer if the player does nothing
Post by: Crimson Wizard on Mon 22/05/2023 20:49:14
Characters already have a "Idle View" mechanic that practically does that, you could use that directly, or use a "dummy" idle view to trigger your code. Set a "idle view" and configure "idle delay" for a character. Then in "repeatedly_execute" test whether idle view had started, and do your thing.

Code (ags) Select
function repeatedly_execute()
{
    if (player.View == player.IdleView) {
         // your actions
    }
}

Relevant articles in the manual:

https://adventuregamestudio.github.io/ags-manual/Character.html#characteridleview
https://adventuregamestudio.github.io/ags-manual/Character.html#charactersetidleview
Title: Re: Start a timer if the player does nothing (SOLVED)
Post by: PERXEO on Tue 23/05/2023 09:40:24
oh thanks! I solved it!!
Title: Re: Start a timer if the player does nothing (SOLVED)
Post by: Khris on Tue 23/05/2023 11:09:48
Without the idle mechanic you could do this:

int idleFrames;

  // inside on_mouse_click
  idleFrames = 0;

  // inside repeatedly_execute
  idleFrames++;
  if (idleFrames >= GetGameSpeed() * 10) ... // 10 seconds idling

This works because during a blocking interaction like examining something, rep_ex doesn't run, so the timer will correctly start to run again as soon as the game returns to idling.