Jump to content
Sign in to follow this  
GeneZ

How do I pause a Timerinit() function

Recommended Posts

GeneZ

so I have this code

While 1 
        If TimerDiff($TransTimer) > 120000 Then
            somefunction()
            $TransTimer = TimerInit()
        EndIf
WEnd

how do I make a hotkey to pause and unpause this.

Share this post


Link to post
Share on other sites
tannerli

you could use something like this...

$TransTimer = 0
$pause = 0

HotKeySet("{PAUSE}", "togglepause")

While 1
    If TimerDiff($TransTimer) > 1000 Then
        If $pause = 0 Then somefunction()
        $TransTimer = TimerInit()
    EndIf
WEnd

Func somefunction()
    ConsoleWrite("TEST" & @CRLF)
EndFunc

Func togglepause()
    If $pause = 0 Then
        $pause = 1
    Else
        $pause = 0
    EndIf
EndFunc

or just use an idle loop where you can jump into during the pause...

Share this post


Link to post
Share on other sites
GeneZ

uhm thanks but I actually wanted to pause the timer. i mean so when i unpause it, it would start when it stopped. like for example i had the timer for 10 seconds and when I paused it at 7 seconds and unpaused it later the timer will continue from where it stopped. I don't know if I'm explaining this correctly my english isn't that good sorry.

Share this post


Link to post
Share on other sites
cageman

what you can do is add a global variable that remembers the time that has passed and another global for the timer. When you pause the script it gets the timerdiff() and sums that up with the value of the time that has passed from a previous timer. When you unpause you re-initiate the timer.

Edited by cageman

Share this post


Link to post
Share on other sites
tannerli

this should do what you want:

$pause = 0
$pausetime = 0

HotKeySet("{PAUSE}", "togglepause")

$TransTimer = TimerInit()

While 1
    If TimerDiff($TransTimer) + $pausetime > 10000 Then
        If $pause = 0 Then somefunction()
        $TransTimer = TimerInit()
    EndIf
WEnd

Func somefunction()
    ConsoleWrite("TEST" & @CRLF)
EndFunc

Func togglepause()
    If $pause = 0 Then ;Enable pause
        $pausetime = TimerDiff($TransTimer) ;Backup the timer for later use...
        $pause = 1
    Else
        $TransTimer = TimerInit()
        $pause = 0
    EndIf
EndFunc
Edited by tannerli

Share this post


Link to post
Share on other sites
GeneZ

Thanks thats what I needed. :blink:

btw I dont want to spam the forums but is it possible to have a GUI that has a textbox that just shows the console so when I compile it still has a console?

Edited by GeneZ

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.