# 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)?

##### 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```

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

## Create an account

Register a new account

×

• Wiki

• Back

• Git