Jump to content
Sign in to follow this  
MyEarth

Replace Sleep() in a loop

Recommended Posts

MyEarth

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

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
MyEarth

Thanks Yoda-Jos but not work, i don't see any ConsoleWrite. Probably because the $itimer is reset every 10ms and never goes to 1000ms

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  

×