hcI Posted March 20, 2017 Share Posted March 20, 2017 (edited) Hello everyone ! I'm making a little program who remind you every 2h to make a pause but i have a serious problem : The timer don't start from 0. It start from a weird value : 131XXXX when X is my timer and 131 increase with my timer and when i close my app and i start it again, the 131 still here and if i close the app with, for exemple 135XXXX, when i re-launch it it's not 131 but 135... Like if the first 3 weird number were saved.. Here's my code, you might not understand the sentence because it's in french Spoiler MsgBox(262144,"WorkOnScreen","L'application a bien été lancée") Opt("TrayMenuMode", 3) Dim $trQuit = TrayCreateItem("Quitter") TraySetIcon("WorkOnScreen_white.ico") Dim $chrono_time = TimerInit() Dim $msgAnswer While 1 Switch TrayGetMsg() Case $trQuit $msgAnswer = MsgBox(262180,"WorkOnScreen","Êtes-vous sûr de vouloir quitter l'application ?") If $msgAnswer = 6 Then Exit EndSwitch If $chrono_time = 7200000 Then MsgBox(262192,"WorkOnScreen","Attention vous avez passé 2 heures sur l'ordinateur !" & @CRLF & "Pensez à faire une pause.") $chrono_time = TimerInit() EndIf WEnd Also, my program have a tray menu to close itself. If someone know why it's doing this.. Edited March 20, 2017 by hcI Topic solved Link to comment Share on other sites More sharing options...
Luigi Posted March 20, 2017 Share Posted March 20, 2017 (edited) Try this... Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) Local $trQuit = TrayCreateItem("Quitter") TraySetIcon("WorkOnScreen_white.ico") TrayItemSetOnEvent($trQuit, "Quit") ;~ AdlibRegister("Alert", 7200000) ; 2 hours AdlibRegister("Alert", 15000) ; 1000 miliseconds * 15 = 15 seconds While Sleep(15) ; delay 15 miliseconds to prevent high cpu use WEnd Func Alert() MsgBox(262192,"WorkOnScreen","Attention vous avez passé 2 heures sur l'ordinateur !" & @CRLF & "Pensez à faire une pause.", 5) EndFunc Func OnExit() AdlibUnRegister("Alert") EndFunc Func Quit() Exit EndFunc Edited March 20, 2017 by Luigi Xandy 1 Visit my repository Link to comment Share on other sites More sharing options...
Xandy Posted March 20, 2017 Share Posted March 20, 2017 (edited) #include <GuiConstantsEx.au3> $timer = 0 $timer_len = 1000 * 5; 5 seconds $hGui = guicreate("", 320, 200) guisetstate() do $msg = guigetmsg() if timerdiff($timer) > $timer_len then beep() $timer = timerinit(); restart the timer endif until $msg = $gui_event_close 5 second beep timer Edited March 20, 2017 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
hcI Posted March 20, 2017 Author Share Posted March 20, 2017 Wow thanks you really much ! Luigi, you make me discovered the AdLibRegister And maybe guys you know why it was doing it ? Link to comment Share on other sites More sharing options...
Xandy Posted March 20, 2017 Share Posted March 20, 2017 (edited) Yeah because TimerInit() returns a timestamp (I think) which is different from a timer length decimal number. Edited March 20, 2017 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Xandy Posted March 20, 2017 Share Posted March 20, 2017 You should use TimerDiff($timestamp) to calculate timer differences. See my example above: if timerdiff($timer) > $timer_len then Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
hcI Posted March 20, 2017 Author Share Posted March 20, 2017 1 minute ago, Xandy said: Yeah because TimerInit() returns a timestamp (I think) which is different from a timer length integer. Oh okay thanks now i undertstand Thanks you again guys ! 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