Sign in to follow this  
Followers 0
Newb

[SOLVED] Weird timer behaviours

8 posts in this topic

#1 ·  Posted (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 :x Any suggestion to make it work?

Edited 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.

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

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?


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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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: :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 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.

Share this post


Link to post
Share on other sites

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 ...
 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0