Sign in to follow this  
Followers 0
powerpoison

@error and PixelSearch

3 posts in this topic

Hello, it is me again :S sorry

well i want to do a double pixel check, one where the first pixelsearch is right and another one right below it ( just 1 pixel)

so something like:

$var=PixelSearch(420,250,800,550,0x946880)
 While @error
 $var=PixelSearch(420,250,800,550,0x946880)        ;// this will continue to search if the script actually don't find the right pixel
 WEnd
 If Not @error Then
 $var2=PixelSearch($var[0]-1,$var[1]-1,$var[0]+1,$var[1]+1,0x976880)
 While @error
 $var2=PixelSearch($var[0]-1,$var[1]-1,$var[0]+1,$var[1]+1,0x976880)        ;// this will continue to search if the script actually don't find the right pixel
 WEnd
 if $var2[1]-$var[1]=1 then
 ;//pixel couple was found
Endif

the problem is, will using @error like this actually collide? i mean, once in the second while, after the first check passed setting @error to 0 when it will become 1 again (or true i dunno what it returns) while the first while take in again confinig the script in a infinite loops?

Also if that particular couple of pixels are found many times (lets say 3 times) will the $var array store all the pixels coord or just the first one? (like $var[2] $var[3] being the second result and $var [4] $var[5] the third?)

is there a faster/smarter way to check for a couple of pixels one over the other?

thanks for the help ^^

Share this post


Link to post
Share on other sites



I've been trying to do something similar but i have hard time getting it to work properly. Mine is pretty much the same it will look for say 3 pixels. The problem is finding the first one and then find the second/third after that. I was hacking away at the x+1/y+1. In the end it would find the first pixel color then work its way downwards to the left and then end once it hit the bottom. As you can see that isn't very helpful if there are more pixels to be found on the right side of the screen.

It's great if you know exactly where the pixels are located but if you don't it's going to get tough. The tricky part with pixelsearch is that it will stop at the first pixel it finds and call it a day. The difficult part is to get it to continue searching until a set of pixels have been found. I thought just adding the previous coordinations to the pixelsearch would help, but it didn't, because i probably did it all wrong. Unlike your code mine had to work with the entire screen which made it a little more complicated.

Maybe someone have made a more complicated version of pixelsearch that allows you to search for an *image* on the screen. I can't find anything like that tho. I've seen some more complex variations of pixelsearch tho. I don't have any code to post of my previous work but it didn't work very well to begin with so i scrapped it. The idea is pretty simple tho.

You look for the first pixel you're interested in using something like $pixel1 = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 5666275) (i'm using a pure red using paint). When it finds the first one it check for the next two using the previous values. Since you know where exactly those two pixels will be at all you need to do is get the color at those exact locations. When the first one matches and the second two... then you have a win and found what you're looking for. Looks so easy when you write it down like this. But my problem was that it worked from the first red pixel it found and then worked its way down to the left, once it hit the bottom it would halt. I just couldn't get it to start the search over but from an increased x-axis. It would just start over from the start for some reason.


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Probably something like this

Local $bflag = False

Do
    Sleep(500)
    $var = PixelSearch(420, 250, 800, 550, 0x946880) ; look for initial pixel
    If Not @error Then ; Found the pixel
        if PixelGetColor($var[0],$var[1]+1) = 0x946880 ; if the pixel directly below the one you found is equal to 0x946880
            $bflag = True ; we found pixel and the one below it is correct
        EndIf
    EndIf
Until $bflag

MsgBox(0,0,"Yay") ; The End

EDIT:

added a sleep

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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