Jump to content

Any way to pause a timer ?


Recommended Posts

Hi,

I'm trying to find a way to pause a timer ( TimerInit() ) but haven't been successfull so far ... i've tried searching the forums but i couldn't find anything that could help me.

The script is supposed to be a stopwatch, I'm currently using AdlibEnable to start the timer and AdlibDisable() to stop updating the labels, but i can't find a solution for pausing the timer itself.

Any help will be apreciated :). Thank you for reading. :P

P.S.: Adlib() is the only way i can get the script to work. (so far)

Edited by mexykanu
Link to comment
Share on other sites

can you provide a better explanation to what are you trying to do?

an example code will also be great

You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
Link to comment
Share on other sites

Why don't you just start and stop it and memorize (in a var ofc :) ) and finally add all the ms's together?

For examples:

Edit: This one is a better examples to restart a timerinit (like its started again)

Dim $timer, $difference = 0

$timer = TimerInit()
Sleep(500) ; Stop 1
$difference = $difference + TimerDiff($timer)
$timer = TimerInit()
Sleep(243) ; Stop 2
$difference = $difference + TimerDiff($timer)
$timer = TimerInit()
Sleep(600) ; Stop 3
$difference = $difference + TimerDiff($timer)

MsgBox(0,"",$difference)
Edited by Triblade

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

The script will simulate a Stopwatch.

Here's what i'm trying to do:

; A. The function that starts the stopwatch
Func start_timer()
    $Init0 = TimerInit()
    AdlibEnable("show_timer",60)
EndFunc

; B. The function that pauses the stopwatch
Func pause_timer()
    AdlibDisable()
EndFunc

; A. The function that resumes the stopwatch
Func resume_timer()
    AdlibEnable("show_timer",60)
EndFunc

Func show_timer()
    
           ;Seconds [Read] String (From the timer)
    $secz = StringFormat("%.2f", TimerDiff($Init0)/1000)
    $seconds_time=StringSplit($secz,"."); Seconds > GUI
    $milisec_time=StringSplit($secz,"."); Milisec > GUI
    
            GUICtrlSetData($seconds_disp,$seconds_time[1]); Place Seconds into GUI ctrl
    GUICtrlSetData($milisec_disp,$milisec_time[2]); Place Milisec into GUI ctrl

; Script for transforming seconds into minutes
    $minz = StringFormat("%.1f", $seconds_time[1]/60) 
    $minutes_value=StringSplit($minz,".")
    GUICtrlSetData($minutes_disp,$minutes_value[1])
EndFunc

I'm trying to get the Func pause_timer() to pause the TimerInit() function, so that when i press the Resume button, the stopwatch will continue from where it was paused :)

Link to comment
Share on other sites

I just finished messing up your code :)

Dim $Init0, $remember = 0

start_timer()
Sleep(500)
pause_timer()
sleep(100)
resume_timer()
sleep(100)
msgbox(0,"",$remember + Timerdiff($Init0))

; A. The function that starts the stopwatch
Func start_timer()
    $Init0 = TimerInit()
    ;AdlibEnable("show_timer",60)
EndFunc

; B. The function that pauses the stopwatch
Func pause_timer()
    ;AdlibDisable()
    $remember += TimerDiff($Init0)
EndFunc

; A. The function that resumes the stopwatch
Func resume_timer()
    ;AdlibEnable("show_timer",60)
    $Init0 = TimerInit()
EndFunc

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

HotKeySet("^v","Start_timer")
HotKeySet("^c","Pause_timer")
HotKeySet("^b","Resume_timer")
Global $PausedTimer
Global $Init0
while 1 
WEnd

; A. The function that starts the stopwatch
Func start_timer()
    $Init0 = TimerInit()
    AdlibEnable("show_timer",60)
EndFunc

; B. The function that pauses the stopwatch
Func pause_timer()
    AdlibDisable()
    $PausedTimer = TimerInit()
EndFunc

; A. The function that resumes the stopwatch
Func resume_timer()
    AdlibEnable("show_timer",60)
    $Init0 = $Init0 + TimerDiff($PausedTimer) * 3600
EndFunc

Func show_timer()
    consoleWrite(@CRLF & Floor(TimerDiff($Init0)/100))

Simple...

You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
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...