Jump to content

After resuming TimerInit() from pause, time starts from beginning...


Go to solution Solved by jguinch,

Recommended Posts

Hi people,

I've been searching how to solve my problem on the forum but nothing i've tried helped me.

My problem:

When i pause my script after (lets say) 5 secs, the time stops. But when i resume, the time cycle starts all over from the beginning instead if continuing from where it stopped?

I know i have to load the paused time in memory to use it again when i resume, but how?

Could someone please give me a push in the right direction. :thumbsup:

Here is my script:

#include <Date.au3>

Global $TimeToSpend = 30000 ;30 secs.
Global $Pause = 0
HotKeySet("{PAUSE}", "_TogglePause")
HotKeySet("{ESC}", "_Exit")

Local $Timer = TimerInit()
While 1
    Sleep(1000)
    Local $TimeDiff = TimerDiff($Timer) ;Returns the difference in time from a previous call to TimerInit().
    Local $TimeLeft = $TimeToSpend - $TimeDiff
    Local $hour, $min, $sec, $beep, $pos
    if $TimeDiff >= $TimeToSpend Then ;Time is up!
        exit
    Else
        Local $Tooltip_Info = "Time left: "
        $pos = StringLen($Tooltip_Info)
        ToolTip($Tooltip_Info & _ConvertRunningTime($TimeLeft), @DesktopWidth - ($pos * 20), 0)
    EndIf
WEnd

Func _TogglePause()
    If $Pause = 0 Then
        $TimeLeft = $TimeToSpend - $TimeDiff ;Backup the time for later use...
        $Pause = 1
        $Message = "Countdown is paused by user !" & @LF _
        & "Click ""Pause break"" to continue"
        $Splash = SplashTextOn("Paused", $Message, 380, 90, -1, -1, 4, "", 20)
        $Coords = WinGetPos($Splash)
        While $Pause
        Sleep(500)
            ;Start some code
        WEnd
        SplashOff() ;Turns SplashText or SplashImage off.
    Else
        $Timer = TimerInit()
        $Pause = 0
    EndIf
EndFunc   ;==> _TogglePause

Func _Exit()
Exit
EndFunc   ;==> _Exit

Func _ConvertRunningTime($ms)
    Local $hour, $min, $sec, $beep
    _TicksToTime($ms, $hour, $min, $sec)
    If $hour > 24 Then
        $hour = Mod($hour, 24)
    EndIf
        If $hour = 0 And $min <= 5 And $sec = 0 Then ;When 5 minutes left, play ringout.wav every [60 secs].
            If TimerDiff($beep) > 60000 Then ;60000 = Interval time between beebs [1 min.].
                SoundPlay(@WindowsDir & "\media\ringout.wav", 0)
                $beep = TimerInit()
            EndIf
        EndIf
    Return StringFormat("%02i:%02i:%02i", $hour, $min, $sec)
EndFunc   ;==> _ConvertRunningTime
Edited by Meesterlijk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...