Jump to content

PixelSearch


LuisGA
 Share

Recommended Posts

Hello.

I have this little script, in which i use pixelsearch to search for a pixel that is changing constantly.

What im trying to do is to click on a certain spot of the screen when $greycoord[0] (coordinate X) is at the X coordinate 478 but i got this error.

C:\user\?????\?????\?????\test.au3 (30) : ==> Subscript used with non-Array variable.:

if $greycoord[0] = 478 Then

if $greycoord^ ERROR

Here is the script so far.

HotKeySet("{ESC}", "Terminate")

Func Terminate()

Exit 0

EndFunc

While (1)

$greycoord = PixelSearch( 295, 476, 785, 490, 0xB6B6B6, 0)

if $greycoord[0] = 478 Then

Sleep (1500)

MouseClick("left", 240, 484, 10, 0)

EndIf

WEnd

What can i do?.

Link to comment
Share on other sites

Add some error handling. When PixeSearch() fails to find the color, it sets @error and doesn't return an array.

Try this:

If IsArray($greycoord) And ($greycoord[0] = 478) Then

Or this:

If (@error = 0) And ($greycoord[0] = 478) Then

Since the logic is tested left-to-right (outside of parens), when $greycoord is not an array (or error is set) the "And" is already false so no attempt is made to access $greycoord[0].

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Add some error handling. When PixeSearch() fails to find the color, it sets @error and doesn't return an array.

Try this:

If IsArray($greycoord) And ($greycoord[0] = 478) Then

Or this:

If (@error = 0) And ($greycoord[0] = 478) Then

Since the logic is tested left-to-right (outside of parens), when $greycoord is not an array (or error is set) the "And" is already false so no attempt is made to access $greycoord[0].

:)

I understand now ;) thanks for the help, my script works now that i understand a little more about it.
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...