Jump to content
Sign in to follow this  
drummer8603

PixelSearch with Array of Hex Colors

Recommended Posts

drummer8603

Hey everyone!  I'm new to Autoit, especially when it comes to creating and pulling data from Arrays. I've created an array that has two Hex Colors.  I want to use PixelSearch to search the screen for both of these and then click on it if found.  Here's what I've tried so far.

#include <array.au3>
Local $X = 1
Local $Array[2]
$Array[0] = 0xFFE78C ; code for Color 1
$Array[1] = 0xFFF384 ; code for Color 2

While $x <= 10
    HotKeySet ("{ENTER}","_StopItNow")
    $Test1 = PixelSearch (148,86,880,571,$Array); Supposed to check for Color 1 and return coordinates or, if color 1 isn't found, check for color 2 and return the coordinates.
    If Not @error Then
        MouseClick ("primary", $Test1[0], $Test1[1], 1, 0)
        Sleep (750)
    EndIf
WEnd
_ArrayFindAll
Func _StopItNow()
    Exit
EndFunc ;terminate script

Any help would be greatly appreciated!

Thanks!

Share this post


Link to post
Share on other sites
iamtheky

for $i = 0 to 1

    HotKeySet ("{ENTER}","_StopItNow")

    $Test1 = PixelSearch (148,86,880,571,$Array[$i]); Supposed to check for Color 1 and return coordinates or, if color 1 isn't found, check for color 2 and return the coordinates.

    If Not @error Then

        MouseClick ("primary", $Test1[0], $Test1[1], 1, 0)

        Sleep (750)

    EndIf

next

changed it to a for loop, and added the element to the $array in the pixel search... should at least get you on to the next thing thats wrong.  Im assuming that is a rogue _ArrayFindAll that wasnt supposed to still be there.

*you could still wrap your eternal loop around it.  if you are not going to increment $x, just use "while 1 / wend" instead of "while $x<=10 / wend"

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
drummer8603

Thanks!  Yes, the _ArrayFindAll wasn't supposed to be there.  I was searching for options that might help me.  I won't have a chance to test this until later this evening but here's the new code with the changes.

#include <array.au3>
Local $Array[2]
$Array[0] = 0xFFE78C ; code for Color 1
$Array[1] = 0xFFF384 ; code for Color 2

HotKeySet ("{ENTER}","_StopItNow")

While 1
    For $i = 0 to 1
        $Test1 = PixelSearch (148,86,880,571,$Array[$i]); Supposed to check for Color 1 and then, if color 1 isn't found, check for color 2 and return the coordinates.
        If Not @error Then
            MouseClick ("Primary", $Test1[0], $Test1[1], 1, 0)
            Sleep (750)
        EndIf
    Next
WEnd

Func _StopItNow()
    Exit
EndFunc ;terminate script

So with this setup will it search for color 1 first and then, if color 1 isn't found, search for color 2?  For example, if the screen has color 1 and color 2 up, I want it to click on color 1 first, sleep for 750 and then click on color 2 and sleep for 750.

Also, another question is what do I need to change when I increase or decrease the array size (apart from the array information itself)?

Thanks for your help!

Share this post


Link to post
Share on other sites
iamtheky
So with this setup will it search for color 1 first and then, if color 1 isn't found, search for color 2? 

 

 

No it loops through them without regard to success or failure.  You should have an "If success Then exit" line if you dont want it to continue after it finds the target color.

You should probably start a habit of using ubound as your upper limit (that way it requires no knowledge of the last element), F1 that and maybe stick a msgbox(0, '' , ubound($array)) after your declarations.

you will quickly understand all the For loops you see with "For $i = 0 to ubound($Array) - 1" , and then start to understand the slight manipulations necessary when working with 1-based -vs- 0-based Arrays.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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  

×