Jump to content

Recommended Posts

Posted

What I want my script to do is wait until a certain pixel is a certain color, but timeout the search after 5 seconds. Waiting for a pixel I can do, and I have this:

Func PixelColor(ByRef $xcoord, ByRef $ycoord, ByRef $pixelcolor)
    Do
  $pixel = PixelGetColor($xcoord,$ycoord)
    Until $pixel = $pixelcolor
EndFunc

But I want it to stop searching after, say, 5 seconds. I tried:

Do
          $timer = TimerStart()
  $pixel = PixelGetColor($xcoord,$ycoord)
  $dif = TimerStop($timer)
    Until $pixel = $pixelcolor OR $dif > 2000

But that just restarts the timer every time.

Help? Please?

Posted

You need to move the timer start outside the do loop

i.e.

$timer = TimerStart()
Do
  $pixel = PixelGetColor($xcoord,$ycoord)
  $dif = TimerStop($timer)
Until $pixel = $pixelcolor OR $dif > 2000

GrahamS

Posted (edited)

Won't that start the timer outside the loop, then try to stop the timer over and over?

*tries it out*

EDIT: Whoahey. It works!

Thanks, GrahamS.

Edited by Sunblood
Posted

Won't that start the timer outside the loop, then try to stop the timer over and over?

*tries it out*

EDIT: Whoahey.  It works!

The function seems to be misnamed. The documentation states

Returns a difference in time from a previous call to StartTimer().

Nothing about actually stopping the timer. In fact, although I haven't inspected the code, I reckon that TimerStart just stores the machine's current time and TimerStop does a simple subtraction :whistle:

Thanks, GrahamS.

You're welcome

GrahamS

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...