Sign in to follow this  
Followers 0
Sunblood

Stopping Then Restarting A Timer?

4 posts in this topic

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?


Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

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  
Followers 0