Pause GETTIMERALL

Previous topic - Next topic

Kitty Hello

Hi,

sometimes you want GETTIMERALL based movement, but then you pop a menu open, and after the close of the menu you see that the player dies because of "out of time" events.

Here's a version of GETTIMERALL() that you can pause:
Code (glbasic) Select

LOCAL t
WHILE TRUE
t = GetMyTimerAll()

IF MOUSEAXIS(3) THEN EnableTimer(TRUE)
IF MOUSEAXIS(4) THEN EnableTimer(FALSE)
PRINT INTEGER(t/1000), 0,0
SHOWSCREEN




WEND



GLOBAL gTimerOffset% = 0
GLOBAL gTimerStopTime% = 0
GLOBAL gTimerEnabled% = FALSE

FUNCTION EnableTimer%: bEnable%
IF bEnable = gTimerEnabled% THEN RETURN

IF bEnable%
DEC gTimerOffset%, gTimerStopTime - GETTIMERALL()
gTimerEnabled = TRUE
ELSE
gTimerStopTime = GETTIMERALL()
gTimerEnabled = FALSE
ENDIF
ENDFUNCTION


FUNCTION GetMyTimerAll%:
IF gTimerEnabled%
RETURN GETTIMERALL() - gTimerOffset%
ELSE
RETURN gTimerStopTime% - gTimerOffset%
ENDIF
ENDFUNCTION


Make sure you "enable" before you start.