Jump to content

How to loop pixelsearch?


Recommended Posts

OMG, I've been thinking of ways to do this and it's giving me a headache.

This is my script as it is:

$var1 = MouseClick("left", 1109, 1003, 1)
MouseClick("left", 1109, 1003, 1)
MouseClick("left", 974, 837, 1)

    PixelSearch(0, 0, 0, 0, 0xC7C7C7)
    If @error Then
        {I don't know what to put here}
    EndIf
    If Not @error Then
        $var1
    EndIf

What do I do, put whiles or something? I dunno :idea:

The thing I hate is that I knew all this before, but I just forgot over the months :) If only I had my script I made...

Edited by miketh2005
Link to comment
Share on other sites

Nvm, I think I got it. I use Else instead and loop it...

There are several issues with your script already, without even doing much of anything...

PixelSearch(0, 0, 0, 0, 0xC7C7C7)

This is doing a pixelsearch on a box of zero dimension. Also, just to keep error low, you should include a step within the search.

IE

PixelSearch(0, 0, 500, 500, 0xC7C7C7, 50)

The last number "50" tells autoit that there will be a variation of 50 between what it sees and what you're checking.

Moving on...

If @error Then
        ;I don't know what to put here}
EndIf
If Not @error Then
        $var1
EndIf

Generally you want to reverse the if-statements you've made, just for redundancy sake. Also, don't end the if-statement, use ElseIf.

IE

If Not @error Then
         ;<======THE COMMANDS YOU WISH TO ISSUE IF THE PIXELSEARCH IS SUCCESSFULL====>
ElseIf @error Then
         ;<======THE COMMANDS YOU WISH TO ISSUE IF THE PIXELSEARCH IS UNSUCCESSFULL====>
EndIf

now, on to your question... to "loop" something, there are many ways, but my personal favorite is the while loop:

IE

While 1
     ;COMMANDS

WEnd

Also, you can add limits to it as well.

Local $i = 0

While $i <= 50
     ;COMMANDS
$i += 1
WEnd
Edited by Neno
Link to comment
Share on other sites

There are several issues with your script already, without even doing much of anything...

PixelSearch(0, 0, 0, 0, 0xC7C7C7)

This is doing a pixelsearch on a box of zero dimension.

Thanks for your help. How do I get rectangle coords? I just know how to get x and y from AutoIt Mouse Info.

Thanks.

Link to comment
Share on other sites

In your pixelsearch

PixelSearch(0, 0, 0, 0, 0xC7C7C7)

the first set of 0,0 is the top left corner of your search area (x,y)

the second 0,0 is the bottom right corner (x,y) and there is your rectangle

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Thanks for your help. How do I get rectangle coords? I just know how to get x and y from AutoIt Mouse Info.

Thanks.

From helpfile that comes with autoit (In SciTE Press F1):

PixelSearch ( left, top, right, bottom, color [, shade-variation [, step [, hwnd]]] )

Use Au3Info.exe to grab BOTH sets of coords.
Link to comment
Share on other sites

To a continous loop u can use to:

While 1
Sleep (50)
Wend

before your code

....To the "Then" command...u must to write what u want:

MouseMove...or anny KeyDown..etc...

What really your script does?

Ah!....the Var in

PixelSearch (50,50,500,500,0xC7C7C7,x)

The "x" on the code is how many color variations may have

I read ... I update ... I learn ...
Link to comment
Share on other sites

Hi guys, thanks. I tried this:

$var1 = MouseClick("left", 1109, 1003, 1)

MouseClick("left", 1109, 1003, 1)
MouseClick("left", 974, 837, 1)

Func bot()
    While 1 ;a simple loop, that is always on when bot = 1
        $coord = PixelSearch(146, 224, 359, 265, 0x008000)
        If @error Then ;it's better to do, if it fails first
            ContinueLoop
        Else ;Else function, meaning if that doesn't happen, then do this
            MouseClick("left", 1109, 1003, 1)
            Exit
        EndIf

    WEnd
EndFunc   ;==>bot

But it doesn't loop. It just exits if it doesn't see that color. What's wrong? Thanks.

EDIT: Oh, is it because I didn't call the function?

Edited by miketh2005
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...