Sign in to follow this  
Followers 0
rylorg

"cool down" in script

5 posts in this topic

I'm working on a fairly simple script and i need a little help, I have it set so when it see's a pixel that is a certain color it does some stuff, but the pixel I'm getting lingers and it does the stuff 3 or 4 times in a row. How can i put a "cool down" on it with out pausing the whole script?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hard to say without seeing your script, but throwing in a little Sleep() probably would do it. Not sure if that'd work for you... depends on what you mean by "with out pausing the whole script."

Edited by xcal

Share this post


Link to post
Share on other sites

Without seeing your script (people think we are telepathic :whistle:) I could suggest a variable that gets toggled.

I assume you have something like a while loop that continuously checks for the pixel colour, well within your IF statement add in another IF checking variable that you set to TRUE previously, when it hits that IF statement, set the variable to FALSE. Then when the IF for your pixel colour returns true it will skip the second IF until the variable is set back to TRUE, which you do by ELSE'ing off the first IF statement so that when the pixel colour does not exist, it sets the variable back to TRUE.

Something like:

$b_KeepSearching = true
...
While 1
  ...
  If PixelColor(etc) Then
    If $b_KeepSearching Then
      $b_KeepSearching = False
      ...Do your thang...
    EndIf
  ElseIf
    $b_KeepSearching = True
  EndIf
  ...
WEnd
...

Share this post


Link to post
Share on other sites

While this is a valid answer:

$b_KeepSearching = true
...
While 1
  ...
  If PixelColor(etc) Then
    If $b_KeepSearching Then
      $b_KeepSearching = False
      ...Do your thang...
    EndIf
  ElseIf
    $b_KeepSearching = True
  EndIf
  ...
WEnd
...oÝ÷ Øfk&Þmëmz»h­çnqëaz{¦mêè}Æ¥Ëh>,^g­
h®)ì¢g¬Û¶*'° ݲ)ÜyÊ&¦ë^®Æ«z¶­êà¢Z¶f­µéî±ëaɶjëh×6
Global $timer_LastPixel = TimerInit()
Global Const $Cool_Down = 3000 ;3 seconds

While 1
    ;Stuff
    ;More stuff
    If (TimerDiff($timer_LastPixel) > $Cool_Down) Then
        If (PixelGetColor($X,$Y) == $Color) Then
            $timer_LastPixel = TimerInit()
            ;Do Stuff
        EndIf
    EndIf
    Sleep(1) ;Let's not hog the CPU
WEnd

Both methods work and don't pause the whole script. I guess it depends on personal preference and situations.

-CMR

Share this post


Link to post
Share on other sites

"I shall be guided by thee in this" as I have never (not once!) used PixelGetColor for any practical reason. :whistle:

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