Jump to content

How do I pause a Timerinit() function


Recommended Posts

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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...