Jump to content
miketh2005

How to loop pixelsearch?

Recommended Posts

miketh2005

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

Share this post


Link to post
Share on other sites
miketh2005

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

Share this post


Link to post
Share on other sites
Neno

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

Share this post


Link to post
Share on other sites
miketh2005

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.

Share this post


Link to post
Share on other sites
kaotkbliss

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!

Share this post


Link to post
Share on other sites
Neno

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.

Share this post


Link to post
Share on other sites
Fi0da

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 ...

Share this post


Link to post
Share on other sites
miketh2005

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

Share this post


Link to post
Share on other sites
darkjohn20

It should be

While 1
    bot()
WEnd

Func bot()
    ;bot stuff
EndFunc
Edited by darkjohn20

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.