Newb Posted January 20, 2011 Share Posted January 20, 2011 (edited) #Include <Timers.au3> Global $GlobalTimer=_Timer_Init() Global $TimerUpd=99 While 1 If _Timer_Diff($GlobalTimer)>$TimerUpd Then ToolTip(_Timer_Diff($GlobalTimer),500,500) $TimerUpd+=99 Sleep(100) WEnd Simple script, weird outcome. It should run a function everytime the timer reachs a certain time amount. Problem: If i keep the $timerupd variable (which holds the current timer limit to where it must trigger the required function, Tooltipo for this example) behind the range of Sleep time or slightly higher, it works, else it doesn't. Example: Try yourself giving values between 50-110 to $Stimerupd and the tooltip wil pop out, else it wont. I thought that this happens because the While loop, after the sleep command, totally exits from the while loop, then starts it over (I need the while loop because it's part of a GUI, and I need it to keep it open) so, if I set the timerupd to a value higher than the sleep argument, the script won't work. The fact that I can put $timerupd slightly higher than Sleep comes from the fact that autoit isn't precise to the millisecond, so the while loop ends slightly in delay, and i make the Tooltip run in that "Delay limbo". What I don't get is why it doesn't works... Timer value is stored externally and should be read immediately, and in case, ToolTip updated... Well i think u got what I mean Any suggestion to make it work? Edited January 20, 2011 by Newb I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 20, 2011 Developers Share Posted January 20, 2011 I don't get what you are trying to do here and can understand that this can fail. When your Sleep is actually shorter than 10o the If will never be true. Normally I would think you want to add the 99 only to $TimerUpd when the If is true. Jos 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...
Newb Posted January 20, 2011 Author Share Posted January 20, 2011 I don't get what you are trying to do here and can understand that this can fail.When your Sleep is actually shorter than 10o the If will never be true.Normally I would think you want to add the 99 only to $TimerUpd when the If is true.JosWhat I'm trying to do is:I have a _RefreshWebPage() Udf function I made (not true, just making an example)I initialize a timerI run a while loop with a sleep to keep the script openIn the while loop, a _timer_Diff must check when a specified time is passed (for example 3 seconds)If the 3 seconds are passed, then refresh the page, else keep going with the while loopEnd of the loopStart overSo basically I need a script that runs a function every 3 seconds (in this example i say 3 seconds, but time can be any)got it? I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 20, 2011 Developers Share Posted January 20, 2011 (edited) I would use Adlib functions for that or as I mentioned just do what you did, but only add/change the timer value when the If is true, not each loop. Jos Edited January 20, 2011 by Jos 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...
smartee Posted January 20, 2011 Share Posted January 20, 2011 What I'm trying to do is: I have a _RefreshWebPage() Udf function I made (not true, just making an example) I initialize a timer I run a while loop with a sleep to keep the script open In the while loop, a _timer_Diff must check when a specified time is passed (for example 3 seconds) If the 3 seconds are passed, then refresh the page, else keep going with the while loop End of the loop Start over So basically I need a script that runs a function every 3 seconds (in this example i say 3 seconds, but time can be any) got it? try something like Global $timeStamp=TimerInit() Global $timeLimit=3000;3secs While 1 If (TimerDiff($timeStamp)>$timeLimit) Then MsgBox(64,"Info","3 secs up press OK to time again.");function to execute $timeStamp=TimerInit() EndIf WEnd Link to comment Share on other sites More sharing options...
Newb Posted January 20, 2011 Author Share Posted January 20, 2011 (edited) JOS! It's all my fault, stupid error.... Sorry but It's the whole day I'm on this script and I suppose my mind is tired The first script is working awesomely, but in your words lies the solution: only add changet he timer value when the If is true, not each loop. That IS the error, the timer was continually increased at every loop, so it would never reach the TimerDiff value.... God, what a shame :idiot: Thanks for the fast help. try something like Global $timeStamp=TimerInit() Global $timeLimit=3000;3secs While 1 If (TimerDiff($timeStamp)>$timeLimit) Then MsgBox(64,"Info","3 secs up press OK to time again.");function to execute $timeStamp=TimerInit() EndIf WEnd Not what I needed because it lacks the sleep inbetween the while. Anyway, I solved it, it was a stupid error of mine. Thanks. Edited January 20, 2011 by Newb I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
MvGulik Posted January 20, 2011 Share Posted January 20, 2011 Let there be light. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Newb Posted January 20, 2011 Author Share Posted January 20, 2011 Let there be light. Hopefully.... I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. 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