Sign in to follow this  
Followers 0
Knight

Pixelsearch: Find coordinates of occurrence.

2 posts in this topic

Hi,

Currently I have a script that searches the screen for a specific color using PixelSearch(). Once the color is found a series of PixelGetColors() are used based off the result of the PixelSearch() to verify the correct pixel.

While 1
    $rFind_1 = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 10857133)
    If @Error = 1 Then
        MsgBox(0, "Error", "Color not found!")
        ExitLoop
    EndIf
        
    $rFind_2 = PixelGetColor($rFind_1[0] + 115, $rFind_1[1] - 6)
    $rFind_3 = PixelGetColor($rFind_1[0] + 171, $rFind_1[1] + 266)
    
    If $rFind_2 = 11114078 And $rFind_3 = 8077617 Then
        MsgBox(0, "Success", "Success!")
        ExitLoop
    Else
        ContinueLoop
    EndIf
WEnd

It works flawlessly IF the pixelsearch is correct the first time. However if it gets a match and the 2 pixelgetcolors are wrong then when PixelSearch() searches again it finds the exact same location.

So my question is: How would I go about searching for the 2nd+ occurrence of the pixel until everything matches up?

Thanks,

-JKnight

Share this post


Link to post
Share on other sites



$rOccurrence = 0

While 1
    $rFind_1 = PixelSearch($Window_Data[0], $Window_Data[1] + $rOccurrence, $Window_Data[2], $Window_Data[3] - $rOccurrence, 10857133, 3, 1)
    If @Error = 1 Then
        MsgBox(0, "Error", "Color not found!")
        ExitLoop
    EndIf
    
    $rFind_2 = PixelGetColor($rFind_1[0] + 115, $rFind_1[1] - 6)
    $rFind_3 = PixelGetColor($rFind_1[0] + 171, $rFind_1[1] + 266)
    
    If $rFind_2 = 11114078 And $rFind_3 = 8077617 Then
        MsgBox(0, "Success", "Success!")
        ExitLoop
    Else
        $rOccurrence = $rFind_1[1] + 1
        ContinueLoop
    EndIf
WEnd

I've tried to solve the problem by changing the pixelsearch to exclude the area above where the last pixelsearch succeeded but did not match my checks. This works SOMEWHAT. however, if there is a pixel that matches on the same line that is before the one I am looking for, it will fail..

I am still looking for more ideas that are fail-safe.

-JKnight

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