Jump to content

A Question regarding the PixelSearch function.


Recommended Posts

Hello friends ; ) !
I hope this is the right forum to use

Technically i'm new to AutoIT, so i'm always using the example found in the Help file for my functions

For the PixelSearch function, it's something like this ..

Local $aCoord = PixelSearch(x , y , x , y , 0xFF0000)
If Not @error Then
    MsgBox(0,"Found it", "Pure red")
EndIf

What i want to do is put multiple pixelsearchs in If, ElseIf etc ..... EndIf condition ..
i tried few stuff like 
 

If Pixelsearch (x,y,x,y,0x000000) = True Then
; Code
End If

but it never worked .. 
i tried this too ..
 

If PixelSearch (x,y,x,y,0x00000) = Not @Error Then
;code 
EndIf

same thing .. 
My ideal code would be 

If PixelSearch_1 Then
............
ElseIf PixelSearch_2 Then
............
ElseIf PixelSearch_3 Then
............
ElseIf PixelSearch_4 Then
...........
EndIf

but i don't know how to write the code properly for it to work, i hope one of you could guide me in this & Thanks in advance.

Link to comment
Share on other sites

Something like this :

Local $x = 100, $y = 100
Local $aCoord = PixelSearch($x , $y , $x+150 , $y+150 , 0xFF0000)
If Not @error Then
  MsgBox ($MB_SYSTEMMODAL,"","Pure Red found at " & $aCoord[0] & "/" & $aCoord[1])
Else
  $aCoord = PixelSearch($x , $y , $x+150 , $y+150 , 0x00FF00)
  If Not @error Then
    MsgBox ($MB_SYSTEMMODAL,"","Pure Green found at " & $aCoord[0] & "/" & $aCoord[1])
  Else
    $aCoord = PixelSearch($x , $y , $x+150 , $y+150 , 0x0000FF)
    If Not @error Then
      MsgBox ($MB_SYSTEMMODAL,"","Pure Blue found at " & $aCoord[0] & "/" & $aCoord[1])
    Else
      MsgBox ($MB_SYSTEMMODAL,"","No color found")
    EndIf
  EndIf
EndIf

If you only want to search for a single pixel, use PixelGetColor () instead...

Link to comment
Share on other sites

Link to comment
Share on other sites

I used to use .. PixelSearch(100,200,100,200,0x00000) to look for a single pixel, meanwhile i could have used PixelGetColor() all along 
Damn ... thank you so much, that's exactly what i needed

Now, i figured out how to do it !
 

While 1

Local $Color = PixelGetColor (x,y)

If $Color = 0 Then
 MsgBox (0, "The color is","Black")
ElseIf $Color = 255 Then
 MsgBox (0, "The color is","Blue")
ElseIf $Color = 16711680 Then
 MsgBox (0, "The color is","Red")
EndIf

;All colors must be written in decimal form

 

Link to comment
Share on other sites

9 minutes ago, Nine said:

If you got multiple colors to search, you could also make it in a loop (with a Const $array) instead of using embedded IF.  Would make it more compact and readable.

Oh, naa not really, only got few colors to deal with 
But if i stumble into a multi color problem, i'd definitely try a Const $array

Link to comment
Share on other sites

7 minutes ago, Elevenster_Loading said:

;All colors must be written in decimal form

No you can use this notation :

If $color = 0xFF0000 Then

I personally prefer using hex format...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...