Start a timer if the player does nothing (SOLVED)

Started by PERXEO, Mon 22/05/2023 20:28:19

Previous topic - Next topic

PERXEO

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
Code: ags
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...

Crimson Wizard

#1
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
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


Khris

Without the idle mechanic you could do this:

Code: ags
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.

SMF spam blocked by CleanTalk