Jump to content

adding timers in my loops


Recommended Posts

Hi there my name is Emy , I'm a newbie autoit user. With the help of the documentation I successfully made few scripts . Now im trying to learn more by optimizing them,  I want to add timers to my loops so that if the pixel is not found within 10 seconds then exit the script. Again with the help of the documentation i came up with this below , however it does not give me any error but the timer doesn't work it will stay in the pixelsearch loop for ever. Im kinda stuck there , i tried several other things but no success either. Any help would be greatly appreciate

  1. #include <MsgBoxConstants.au3>
  2. $start = TimerInit()
  3. Do
  4.     PixelSearch(971,636,977,638,0xFFFFFF) 
  5. Until Not @error Or TimerDiff($start) = 10000
  6.     If TimerDiff($start) = 10000 Then
  7.         MsgBox($MB_OK,"ERROR","TIMEOUT!!!",0)
  8.         Exit
  9.     ElseIf Not @error then
  10.     EndIf
  11. MouseClick("left", Random(800,1100), Random(580,666),5,0)
 
 
 
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

How high is the probability that TimerDiff returns exactly the value 10000?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

7 minutes ago, water said:

How high is the probability that TimerDiff returns exactly the value 10000?

Just a little higher than the probability that it returns exactly 10000 twice, in succeeding statements :)

Until Not @error Or TimerDiff($start) = 10000
    If TimerDiff($start) = 10000 Then

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

I am betting you only changed one.

You need to change both of them. 

#include <MsgBoxConstants.au3>
$start = TimerInit()
Do
    PixelSearch(971,636,977,638,0xFFFFFF)
Until Not @error Or TimerDiff($start) >= 10000
    If TimerDiff($start) >= 10000 Then
        MsgBox($MB_OK,"ERROR","TIMEOUT!!!",0)
        Exit
    ElseIf Not @error then
    EndIf

 

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

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