Timppa 1 Posted October 5, 2015 (edited) Hello again guys!My problem today is (which I encounter everyday (but always solve by myself)) a timer, that does x when the time has end.By far I have this:Func TimerRun() Local $Timer = 0 Local $AllowTimer = 1 If GUICtrlRead($checkboxRunTimer) = 1 And $AllowTimer = 1 Then While 1 SelectTimerAmount() ; <- This is another Func $Timer+=1 ToolTip($Timer) If $Timer == $MaximumTime Then $AllowTimer = 0 $Timer = 0 ToolTip("Time is up!") Sleep(2000) Exit EndIf WEnd EndIf EndFuncOkay, there is the function that "ticks" the Timer, now here is the GUI script:$checkboxRunTimer = GUICtrlCreateCheckbox("Tick to set up Timer", 160, 216, 89, 17) $comboSetTime = GUICtrlCreateCombo("", 468, 385, 89, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "30 seconds|1 min|2 min|3 min|5 min", "30 seconds") ;<- 30 seconds is default GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x000000) Global $MaximumTimeAnd finally, the list where you can choose your time:Func SelectTimerAmount() Switch $comboSetTime Case "30 seconds" $MaximumTime = 30000 ;<- (Like Sleep(30000)) Case "1 min" $MaximumTime = 60000 Case "2 min" $MaximumTime = 120000 Case "3 min" $MaximumTime = 180000 Case "5 min" $MaximumTime = 300000 EndSwitch EndFuncOh and the While 1 script (runs 24/7)If GUICtrlRead($checkboxRunTimer) = 1 Then TimerRun() EndIf Now to my problem. When I run the file, I will see tooltip written only "1" and then it tooltips "Time is up!" and exits.I don't want it to immidiately exit, but to wait until the 30 seconds has passed (if you have chosen 30 seconds).What am I doing wrong? Thanks in advance! EDIT: Wait what... now it works? EDIT2: Now I found my solution.. I had comboSetTime and cSetTime (<- both are combo boxes) and cSetTime was only visible and the comboSetTime were hidden somewhere so of course it did not work because I never defined the amount or ticked the checkbox... Stupid me, anyways here is some kind of example for others if they need a timer You can lock this topic! Edited October 5, 2015 by Timppa Share this post Link to post Share on other sites
computergroove 33 Posted October 6, 2015 Func TimerRun() Local $Timer = 0 Local $AllowTimer = 1 If GUICtrlRead($checkboxRunTimer) = 1 And $AllowTimer = 1 Then While 1 SelectTimerAmount() ; <- This is another Func $Timer+=1 ToolTip($Timer) If $Timer >= $MaximumTime Then; change this to >= $AllowTimer = 0 $Timer = 0 ToolTip("Time is up!") Sleep(2000) Exit EndIf WEnd EndIf EndFuncDont use $timer += 1. Use timerinit and timerdiff functions. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Share this post Link to post Share on other sites
Timppa 1 Posted October 6, 2015 (edited) Func TimerRun() Local $Timer = 0 Local $AllowTimer = 1 If GUICtrlRead($checkboxRunTimer) = 1 And $AllowTimer = 1 Then While 1 SelectTimerAmount() ; <- This is another Func $Timer+=1 ToolTip($Timer) If $Timer >= $MaximumTime Then; change this to >= $AllowTimer = 0 $Timer = 0 ToolTip("Time is up!") Sleep(2000) Exit EndIf WEnd EndIf EndFuncDont use $timer += 1. Use timerinit and timerdiff functions. Why? Wouldn't $Timer+=1 work as well as TimerDiff and TimerInit?Or is there some kind of difference that makes it faster to use them? EDIT: If $Timer >= $MaximumTime Then; change this to >=^ That doesn't matter. $Timer will be equal to $MaximumTime even though if it might go above the integer, but it doesn't matter because it should start to read next line. Edited October 6, 2015 by Timppa Share this post Link to post Share on other sites
yessiree 1 Posted October 6, 2015 AdlibRegister("yourFunction", {timeout in ms})Func yourFunction ; stuffEndFunc Share this post Link to post Share on other sites