SOLVED: Timer for if player NOT moving

Started by Slasher, Sat 12/07/2014 09:01:11

Previous topic - Next topic

Slasher

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

// 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

// import Global ash

import function Walking();


Code: ags

// Global asc

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


Would someone please give me  hand..

Thanks


Scavenger

It's easier to time stuff like this with variables, timers are better for one-off stuff like timed puzzles.

Code: ags

// 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++;
}

Slasher

Thanks Scavenger,

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

many thanks ;)

SMF spam blocked by CleanTalk