Moderators big_daddy Posted June 16, 2006 Moderators Share Posted June 16, 2006 I've been trying to figure this out all day. I made a game with a timer, this part works great. Now what I need is a button that will pause the timer, then when clicked again it continues the timer from the same spot. This is the part that I can't figure out. Just to make things easier I made a small example. expandcollapse popup#include <GUIConstants.au3> Global $Paused = False Global $Timer = 0 GUICreate("", 100, 100) $Button1 = GUICtrlCreateButton("Pause", 25, 40, 50, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Pause() EndSwitch ToolTip("Time: " & _GetTime()) Sleep(50) WEnd Func _Pause() $Paused = True While $Paused If GUIGetMsg() = $Button1 Then $Paused = False EndIf Sleep(10) WEnd EndFunc ;==>_Pause Func _GetTime() If $Timer Then $TimerDiff = Int(TimerDiff($Timer) / 1000) Return $TimerDiff Else $Timer = TimerInit() EndIf EndFunc ;==>_GetTime Func _Exit() Exit EndFunc ;==>_Exit Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 17, 2006 Moderators Share Posted June 17, 2006 Damn, I thought this was a simple logic issue, I was going to say, just user TimerStop() but that didn't work (and it isn't in the help file anymore but it is in the keywords list for SciTe) Anyway, try this and see if it suits your needs:expandcollapse popup#include <GUIConstants.au3> Global $Paused = False Global $Timer = 0, $PausedTimer = 0, $Timer2 = 0 GUICreate("", 100, 100) $Button1 = GUICtrlCreateButton("Pause", 25, 40, 50, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Pause() EndSwitch ToolTip("Time: " & _GetTime(), 0, 0) Sleep(50) WEnd Func _Pause() $Paused = True _PauseTime() While $Paused If GUIGetMsg() = $Button1 Then $Paused = False Sleep(10) WEnd EndFunc ;==>_Pause Func _GetTime() If $Timer Then Return Int(TimerDiff($Timer) / 1000) + $PausedTimer ElseIf Not $Timer2 And $PausedTimer Then $Timer2 = TimerInit() Return $PausedTimer ElseIf $Timer2 And $PausedTimer Then Return Int(TimerDiff($Timer2) / 1000) + $PausedTimer EndIf $Timer = TimerInit() EndFunc ;==>_GetTime Func _PauseTime() If Not $Timer2 Then $PausedTimer += Int(TimerDiff($Timer) / 1000) $Timer = 0 Else $PausedTimer += Int(TimerDiff($Timer2) / 1000) $Timer2 = 0 EndIf EndFunc Func _Exit() Exit EndFunc ;==>_Exit Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MHz Posted June 17, 2006 Share Posted June 17, 2006 Damn, I thought this was a simple logic issue, I was going to say, just user TimerStop() but that didn't work (and it isn't in the help file anymore but it is in the keywords list for SciTe) Scite4AutoIt3 tries to be compatible for v3.... versions of AutoIt. This would allow you to use older versions that have no COM, Gui etc. Link to comment Share on other sites More sharing options...
Busti Posted June 17, 2006 Share Posted June 17, 2006 Func TimerPause($timer) $currentDiff = TimerDiff($timer) TimerStop($timer) return $currentDiff Endfunc Func TimerRunFromPause($timerpause) return TimerInit( $Timerpause ) Endfunc would this work ? My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
Developers Jos Posted June 17, 2006 Developers Share Posted June 17, 2006 Global $SaveDiff = 0 $t = TimerInit() Sleep(1000) ConsoleWrite(TimerPause($t) & @LF) Sleep(1000) ; $t = TimerInit() Sleep(1000) ConsoleWrite(TimerPause($t) & @LF) Sleep(1000) ; $t = TimerInit() Sleep(1000) ConsoleWrite(TimerPause($t) & @LF) Func TimerPause($timer) $SaveDiff = $SaveDiff + TimerDiff($timer) TimerStop($timer) Return $SaveDiff EndFunc ;==>TimerPause SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 17, 2006 Moderators Share Posted June 17, 2006 Global $SaveDiff = 0 $t = TimerInit() Sleep(1000) ConsoleWrite(TimerPause($t) & @LF) Sleep(1000) ; $t = TimerInit() Sleep(1000) ConsoleWrite(TimerPause($t) & @LF) Sleep(1000) ; $t = TimerInit() Sleep(1000) ConsoleWrite(TimerPause($t) & @LF) Func TimerPause($timer) $SaveDiff = $SaveDiff + TimerDiff($timer) TimerStop($timer) Return $SaveDiff EndFunc ;==>TimerPause Nice Jdeb Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted June 17, 2006 Author Moderators Share Posted June 17, 2006 Thank you! I can't test it right now, but I understand the logic. Link to comment Share on other sites More sharing options...
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