Author Topic: Pause GETTIMERALL  (Read 1957 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10667
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Pause GETTIMERALL
« on: 2010-Jan-25 »
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.