Jump to content
Sign in to follow this  
Borges

How stop a while with another condition?

Recommended Posts

Hello guys, can someone help-me with a simple code?

I want to check a pixel with color green and then click 1x

After I click, will apper a red pixel, then I want to check the green pixel again just when the red pixel disappear...

all this in loop

how can I do that?

HotKeySet("{PAUSE}", "Terminate")

Func checkForPixel()
    Local $test = 0
    PixelSearch(1018, 441, 1018, 441, 0x7A9D76)  ; green pixel
    If Not @error And $test = 0 Then
        MouseClick("left", 1031, 444)
        Sleep(500)
        PixelSearch(1076, 439, 1076, 439, 0xFF0000) ; red pixel appear
        If Not @error Then
            Local $test = 1
        EndIf
        PixelSearch(1076, 439, 1076, 439, 0xAE764B) ; red pixel disappear
        If Not @error Then
            $test = 0
        EndIf
    EndIf
EndFunc   ;==>checkForPixel

While 1
    checkForPixel()
WEnd

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Edited by Jos
Tidied the code of readability

Share this post


Link to post
Share on other sites

Looks like you can remove the last PixelSearch altogether, the function will end, be called again, reset the $test variable and search again for the green pixel.

Share this post


Link to post
Share on other sites
15 hours ago, Sidley said:

Looks like you can remove the last PixelSearch altogether, the function will end, be called again, reset the $test variable and search again for the green pixel.

After some tests, my script it's working the way I wanted it.

HotKeySet("{PAUSE}", "Terminate")
local $test = 0
Func checkForPixel()
   WinWaitActive("NoxPlayer")
PixelSearch ( 1018, 441, 1018, 441, 0x7A9D76) ; green pixel
   If Not @error and $test = 0 Then
      MouseClick("left",1031,444)
      $test = 1
      Sleep(50)
   EndIf
PixelSearch ( 1076, 439, 1076, 439, 0xFF0000) ; red pixel appear
   if Not @error Then
      Sleep(50)
   Else
      $test = 0
   EndIf
EndFunc

while 1
checkForPixel()
WEnd

Func Terminate()
    Exit
EndFunc
13 hours ago, Bert said:

What are you trying to automate? Pixel searching is the worst way to automate. Hooking into the control is much better. We may have what you need ready to go. No point re-inventing the wheel. 

how can I do that, with this "control"?

how it works?

 

Thanks for feedback

 

Edited by Borges

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...