Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Sat 12/07/2014 09:01:11

Title: SOLVED: Timer for if player NOT moving
Post by: Slasher on Sat 12/07/2014 09:01:11
Hi,

There is an area that I am trying to incorporate in to a game and I need some assistance.

Basically a timer measures the time you are NOT moving. If you are not moving then the timer goes up 1 a second per second you are not moving (every time you are not moving).

When the player is moving then the timer stops  etc etc.

I made a variable 'Stopped_Moving' and a function:

Code (ags) Select

// function top Global asc

function Walking()
{
  if(player.Moving)
  {
  SetTimer(3, 0);
  }  else
  {
  Stopped_Moving=(Stopped_Moving +1);
  LNotMoving.Text = String.Format("%d", Stopped_Moving);
  SetTimer(3, 40);
  } 
}


I have imported it:
Code (ags) Select

// import Global ash

import function Walking();


Code (ags) Select

// Global asc

// in function repeatedly_execute_always()
}
if (IsTimerExpired(3))
{
Walking();
}


Would someone please give me  hand..

Thanks

Title: Re: Timer for if player NOT moving
Post by: Scavenger on Sat 12/07/2014 09:22:51
It's easier to time stuff like this with variables, timers are better for one-off stuff like timed puzzles.

Code (ags) Select

// function top Global asc

int walktimer;

function Walking()
{
    if(player.Moving)
      {
          walktimer=0;
      } 
    else if (walktimer > GetGameSpeed ())
      {
          Stopped_Moving += 1;
          LNotMoving.Text = String.Format("%d", Stopped_Moving);
          walktimer = 0;
      }
    else walktimer++;
}
Title: SOLVED: Re: Timer for if player NOT moving
Post by: Slasher on Sat 12/07/2014 09:42:25
Thanks Scavenger,

I was sure there was a better way. Works a treat.

many thanks ;)