Simple Timer

Previous topic - Next topic

XanthorXIII

I'm trying to program a Simple Timer using GETTIMERALL(), does anyone have simple code for calculating time elasped?
Thanks.
Owlcat has wise

Omadan

Just use this my friend.

LOCAL time_at_start%//remember to define this variable as global if you will output time on different functions etc.

*your main loop starts here
PRINT "time_elapsed: "+INTEGER((GETTIMERALL()-time_at_start))/1000,10,10
****************************
It will give you time elapsed and output it as an INT.
If you want float, remove the INTEGER command and play with it to give you float to the decimal place you require.
Hope this is what you want, but if it's not then we will help you further.

Regards
Top Arcade Apps - Best game for mobiles and computers

http://www.toparcadeapps.com

MrTAToad


XanthorXIII

Thanks Guys, both have good information although what MrTAToad got me closer to what I need, just need to rework my code some to get it working and need to plan out how the game will play.
I'm almost to a point to where my game is almost functional.
Owlcat has wise

Slydog

Here's some timer functions that I have been working on.  Nothing fancy.
I haven't tested all of this, so there may be bugs.

Code (glbasic) Select
// Returns ms since program start, or last 'reset'
// To reset the timer, call 'Timer_All(TRUE)'
FUNCTION Timer_All%: reset% = FALSE
STATIC timer_start%=0
IF reset = TRUE THEN timer_start = GETTIMERALL()
RETURN GETTIMERALL() - timer_start
ENDFUNCTION

// Countdown Timer
// Pass this function an integer that holds the current timer value.
// Timer variable is updated byref
// Returns TRUE if the timer is still running
// Returns FALSE if the timer has expired
// EXAMPLE:
//   LOCAL wait% = 1000
//   LOCAL delay% = 2000
//   IF Timer_Down(wait) = FALSE
//     . . . 'wait' timer has expired
//     wait = 1000    // reset timer
//   ENDIF
//   IF Timer_Down(delay) = FALSE
//     . . . 'delay' timer has expired
//     delay = 1000   // reset timer
//   ENDIF
FUNCTION Timer_Down%: BYREF time%
DEC time, GETTIMER()
IF time <= 0
time = 0
RETURN FALSE
ELSE
RETURN TRUE
ENDIF
ENDFUNCTION

// Same as 'Timer_Down()' except you pass the 'timer_length' as it automatically resets the timer when expired
// EXAMPLE:
//   LOCAL wait% = 1000
//   LOCAL delay% = 2000
//   IF Timer_Repeat(wait, 1000) = FALSE
//     . . . 'wait' timer has expired
//   ENDIF
//   IF Timer_Repeat(delay, 2000) = FALSE
//     . . . 'delay' timer has expired
//   ENDIF
FUNCTION Timer_Repeat%: BYREF time%, timer_length%
DEC time, GETTIMER()
IF time <= 0
time = timer_length // Reset timer
//time = timer_length-time // Reset timer  (Optional to above to prevent timer drifting)
RETURN TRUE // Timer has ended
ELSE
RETURN FALSE // Timer still executing
ENDIF
ENDFUNCTION
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]