GeneZ Posted July 8, 2010 Posted July 8, 2010 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.
tannerli Posted July 8, 2010 Posted July 8, 2010 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 EndFuncor just use an idle loop where you can jump into during the pause...
GeneZ Posted July 8, 2010 Author Posted July 8, 2010 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.
cageman Posted July 8, 2010 Posted July 8, 2010 (edited) 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 July 8, 2010 by cageman
tannerli Posted July 8, 2010 Posted July 8, 2010 (edited) 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 July 8, 2010 by tannerli
GeneZ Posted July 8, 2010 Author Posted July 8, 2010 (edited) Thanks thats what I needed. 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 July 8, 2010 by GeneZ
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now