Jump to content

Replace Sleep() in a loop


Recommended Posts

Hello. I need to replace a Sleep() with something similar but without Sleep() all the While-WEnd but just the If-EndIf

An example:

HotKeySet("{ESC}", "ESC")
HotKeySet("{F1}", "Var")

Local $iVar1 = 0, $iVar2 = 0

While 1
    ; other things
    Sleep(10)
    If $iVar1 = $iVar2 Then
        Sleep(1000) ; replace this!
        ConsoleWrite("$iVar1 = $iVar2" & @CR)
    EndIf
WEnd

Func Var()
    $iVar2 = 1 ; stop the ConsoleWrite
EndFunc

Func ESC()
    Exit
EndFunc

As you can see i have a main Sleep of 10ms ( in the script is done by GUIGetMsg() ) and another Sleep if a condition found, i want to replace that. I have think to use TimerInt - TimerDiff but for what i have understand i need to put TimerInt OUTSIDE the loop. No i don't want to have two different loop.

Thanks for the help

Link to comment
Share on other sites

  • Developers

Untested but should show an options:

ocal $iVar1 = 0, $iVar2 = 0, $itimer = 0

While 1
    ; other things
    Sleep(10)
    If $iVar1 = $iVar2 Then
        $itimer = TimerInit()
    EndIf
    If $itimer <> 0 and TimerDiff($itimer) >= 1000 Then
        ConsoleWrite("$iVar1 = $iVar2" & @CR)
        $itimer = 0
    EndIf
WEnd

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

  • Developers

Then simply ensure that it isn't reset in each loop by adding a test like:

If $iVar1 = $iVar2 and $iTimer = 0 Then

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...