think Posted January 15, 2008 Share Posted January 15, 2008 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. Link to comment Share on other sites More sharing options...
raer Posted January 15, 2008 Share Posted January 15, 2008 (edited) 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 January 15, 2008 by raer Link to comment Share on other sites More sharing options...
think Posted January 15, 2008 Author Share Posted January 15, 2008 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. Link to comment Share on other sites More sharing options...
raer Posted January 16, 2008 Share Posted January 16, 2008 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). Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now