Jump to content
Sign in to follow this  
Cambo

Screwy Loop? Time something, and not something else...

Recommended Posts

These boards are on fire! And everyone seems to be extremely helpful!

I figured I had one more question pressing on my mind so why not ask it! I'm very new to autoit, and have only been coding altogether for about 5 months, so if the questions I ask seem trivial, please forgive me!

I want some kind of loop that sends a certain defined key (using SEND(), very simple) every 60 secs or so (I normally just do Sleep(Random(60000,65000)) or something) but also is constantly (without the sleep) checking for a string (using my newly learned StringRegExp() :))

Right now I have something like this:

While 1
    Send("{k}")
    Sleep(Random(60000,65000))  
    $lines = FileRead("file.log")

        If StringRegExp($lines, "A|B|C") Then
            Sleep(Random(3000,5000))
            DoSomethingElse()
        EndIf

WEnd

But this only reads the file every 60 seconds. I want it to constantly (no sleep timer) read the file while only every 60 seconds send the key. What else am I missing tonight? ^_^

Thanks again for the wonderful help!

Share this post


Link to post
Share on other sites

You make the execution of the thing that sleeps longer to be conditionally executed:

Send("{k}")
$time = (Random(60000,65000))
$base = TimerInit()
While 1
    If TimerDiff($base) > $time Then
        Send("{k}")
        $time = (Random(60000,65000))
        $base = TimerInit()
    EndIf
    $lines = FileRead("file.log")
    If StringRegExp($lines, "A|B|C") Then
        Sleep(Random(3000,5000))
        DoSomethingElse()
    EndIf
WEnd

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  

×
×
  • Create New...