Jump to content

Using 1 while statement for 2 options


Recommended Posts

Ok, so i have a timer sentance that works perfectly, but now i need it to check for a second time within the first check. What should i edit it to make it wait for an hour and 30 min.

Local $begin = ''
Local $dif = 0

    While 2
        Sleep(10)
        $dif = Int(TimerDiff($begin) / 1000)
        If $dif >= (.5 * 60) Then
            MyFunction2()
            $begin = TimerInit()
        EndIf
    WEnd

How would i edit this to make it wait for also an hour and thirty min, while still watching for the (.5 * 60)?

Link to comment
Share on other sites

You would need two timers since your $dif >= (.5 * 60) expression is resetting the $begin timer. Something like:

$timer1 = TimerInit()
$timer2 = $timer1
While 1
    Sleep(10)
    $dif1 = Int(TimerDiff($timer1) / 1000)
    If $dif >= (.5 * 60) Then
        MyFunction2()
        $timer1 = TimerInit()
    EndIf
    $dif2 = Int(TimerDiff($timer1) / 1000)
    If $dif2 >= 5400 Then ;5400 secs = 1 1/2 hour
        DoSomething()
        $timer2 = TimerInit()
    EndIf
WEnd
Link to comment
Share on other sites

You would need two timers since your $dif >= (.5 * 60) expression is resetting the $begin timer. Something like:

$timer1 = TimerInit()
$timer2 = $timer1
While 1
    Sleep(10)
    $dif1 = Int(TimerDiff($timer1) / 1000)
    If $dif >= (.5 * 60) Then
        MyFunction2()
        $timer1 = TimerInit()
    EndIf
    $dif2 = Int(TimerDiff($timer1) / 1000)
    If $dif2 >= 5400 Then;5400 secs = 1 1/2 hour
        DoSomething()
        $timer2 = TimerInit()
    EndIf
WEnd
Good solution, but that second TimerDiff() needs to use $timer2 vice $timer1.

^_^

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...