Jump to content
Sign in to follow this  
think

help with looping PixelGetColor

Recommended Posts

think

Hello,

I'm having problems getting PixelGetColor to run in a loop until the selected pixel color changes. Here is the part of the script im talking about::

$turncheck = PixelGetColor( 390, 405)

Do $turncheck
 Until $turncheck = 15790321 
   Call("GetAction()")

Essentially what I am trying to acomplish, is to have PixelGetColor repeatedly check the pixel for a change in color. When the color changes to the specified color, I

want it to run the function ( GetAction() ).

After the function returns it's value, and has completed its task, how do I have it enter the loop again ? and so on and so on.

I have also tried making this happen with When and While.

Does that make sense??

Any help or advice with this would be greatly appreaciated. Thank you.

Share this post


Link to post
Share on other sites
raer

Func GetAction()
   MsgBox(0, "Pixel changed", "Pixel changed")
   $value = 10; don't know what value you want to return
   Return $value
EndFunc

Do
  $turncheck = PixelGetColor(390, 405)
  If $turncheck = 15790321 Then
    $value = GetAction()
  ; do something with the value
  EndIf
  Sleep(100); because otherwise the script would make the processor really busy (100%)
Until False

I put the call to PixelGetColor() function and the testing condition (is the pixel color code equal to 157...) into indefinite loop (Do Until False). (In your snippet you check for the color only once, while you have to do it regularly.) But remember you probably want to add some condition to stop the script somewhere. (For instance, add into the GetAction() function or into the loop something like

If $value = [i]something[/i] Then Exit
Edited by raer

Share this post


Link to post
Share on other sites
think

Func GetAction()
   MsgBox(0, "Pixel changed", "Pixel changed")
   $value = 10; don't know what value you want to return
   Return $value
EndFunc

Do
  $turncheck = PixelGetColor(390, 405)
  If $turncheck = 15790321 Then
    $value = GetAction()
 ; do something with the value
  EndIf
  Sleep(100); because otherwise the script would make the processor really busy (100%)
Until False

I put the call to PixelGetColor() function and the testing condition (is the pixel color code equal to 157...) into indefinite loop (Do Until False). (In your snippet you check for the color only once, while you have to do it regularly.) But remember you probably want to add some condition to stop the script somewhere. (For instance, add into the GetAction() function or into the loop something like

If $value = [i]something[/i] Then Exit

Awsome. I never thought of that approach.

With the indefinite loop, will it return to the loop after the funtion is ran?

Other than that, I completely understand your code. Thanks for your help.

Share this post


Link to post
Share on other sites
raer

Awsome. I never thought of that approach.

With the indefinite loop, will it return to the loop after the funtion is ran?

Other than that, I completely understand your code. Thanks for your help.

Of course, because the execution of the script continues with the command right after the function code (command after
$value = GetAction()
which is
EndIf
). You just need to put there some condition to stop the indefinite loop (unless you want to stop the script from Windows tray bar or from Task Manager) - it can be Exit command (which stops the whole script) or ExitLoop (which makes the execution continuing after the Until/WEnd command). ExitLoop must therefore be used within loop, but not within the function (which in fact is not part of the loop).

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.