Sign in to follow this  
Followers 0
alex OF DEATH

Pixel search

8 posts in this topic

Here is my script:

Func go()
    $clickpos = MouseGetPos()
    $color = pixelgetcolor ( $clickpos[0] , $clickpos[1] )
    $Findnew = PixelSearch ( 519, 257, 1031, 593, $color )
    if $findnew > 1 then mouseclick ( "left" , $Findnew[0] & $Findnew[1] )
    endfunc

Okay, so im trying to get a color of an object on the screen, then search an area for that color and click on it.

Im a little bit confused on the pixel search parameters. It's really hard to explain what I think it means, but please just explain what it wants

Also, it says that $findnew is a non array variable. Im pretty sure it is. it MAY just be a mistake because i don't know what pixel search wants.

And "if $findnew > 1 then mouseclick" is all i could think of. I know that it most likely doesn't work like that.

And i want it to loop the "if $findnew > 1 then mouseclick" part. Would a "While 1 <func here> Wend" do that? Can I have it in that same function i posted above?


Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

try with

If IsArray($Findnew) Then Mouseclick("left", $Findnew[0], $Findnew[1])

Edited by newb_powa'

Share this post


Link to post
Share on other sites

If IsArray($Findnew) 1 Then Mouseclick("left", $Findnew[0], $Findnew[1]

...^

Error in expression


Share this post


Link to post
Share on other sites

If IsArray($Findnew) Then Mouseclick("left", $Findnew[0], $Findnew[1]

...^

Error in expression

I didn't remove the "1" ^^

Share this post


Link to post
Share on other sites

No errors, but it doesn't click the color.

I think i just need to loop it.

while 1

Wend

right?


Share this post


Link to post
Share on other sites

No errors, but it doesn't click the color.

I think i just need to loop it.

while 1

Wend

right?

You're right, something like that should work

Func go() ;Search for the color until it find it, then click it and exit loop
    $x = 0
    Do
        $CurrentPos = MouseGetPos()
        $color = pixelgetcolor($CurrentPos[0] , $CurrentPos[1])
        $Coord = PixelSearch(515, 255, 1030, 595, $color)
        If IsArray($Coord) Then
            MouseClick("Left", $Coord[0], $Coord[1], 1, 0)
            $x = 1
        EndIf
        MouseMove($CurrentPos[0], $CurrentPos[1], 0)
    Until $x = 1
EndFunc

If you want it to never stop to run, replace "Do" by "While 1" and "Until $x = 1" by "Wend"

Share this post


Link to post
Share on other sites

Try this so you have an easy way to get out of this endless loop in case the color is not found.

HotKeySet("{ESC}", "StopFunction")
Global $x = 0
go()
Func go() ;Search for the color until it find it, then click it and exit loop
    Do
        $CurrentPos = MouseGetPos()
        $color = PixelGetColor($CurrentPos[0], $CurrentPos[1])
        $Coord = PixelSearch(515, 255, 1030, 595, $color)
        If IsArray($Coord) Then
            MouseClick("Left", $Coord[0], $Coord[1], 1, 0)
            ConsoleWrite("yes" & @CRLF)
            Return 1
        EndIf
        MouseMove($CurrentPos[0], $CurrentPos[1], 0)
    Until $x = 1
    ConsoleWrite("no" & @CRLF)
    Return 0
EndFunc   ;==>go

Func StopFunction()
    $x = 1
EndFunc   ;==>StopFunction

Kohr

Share this post


Link to post
Share on other sites

Okay, cool. it works, thanks. :)


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