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

4 posts in this topic

#1 ·  Posted (edited)

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
    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!
        Local $Tooltip_Info = "Time left: "
        $pos = StringLen($Tooltip_Info)
        ToolTip($Tooltip_Info & _ConvertRunningTime($TimeLeft), @DesktopWidth - ($pos * 20), 0)

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
            ;Start some code
        SplashOff() ;Turns SplashText or SplashImage off.
        $Timer = TimerInit()
        $Pause = 0
EndFunc   ;==> _TogglePause

Func _Exit()
EndFunc   ;==> _Exit

Func _ConvertRunningTime($ms)
    Local $hour, $min, $sec, $beep
    _TicksToTime($ms, $hour, $min, $sec)
    If $hour > 24 Then
        $hour = Mod($hour, 24)
        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()
    Return StringFormat("%02i:%02i:%02i", $hour, $min, $sec)
EndFunc   ;==> _ConvertRunningTime
Edited by Meesterlijk

Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)


Thanks in a Million!!

Sometimes it seems a simple thing.

Thanks m8 :shifty:

This one is solved!

Edited by Meesterlijk

Share this post

Link to post
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