Jump to content

Error: Subscript used with non-Array variable.


Naem
 Share

Recommended Posts

So a small part of my code keeps bugging if the pixel color isn't found, and I cant figure out why. Hopefully someone can help (I'm not very experienced)

Func _FindColor ()
        
    $Coords = PixelSearch(0, 0, @DesktopWidth - 1, @DesktopHeight - 1, 0xFF9632)
    Sleep(Random(700,1000))
    If Not @error Then 
        MouseClick('Left', $Coords[0]+50, $Coords[1]+110, 1, 0)
    EndIf
    
    Sleep(Random(700, 1000))
EndFunc

This is the error message:

C:\Users\Jason\Desktop\Show of the month bot.au3 (79) : ==> Subscript used with non-Array variable.:

MouseClick('Left', $Coords[0]+50, $Coords[1]+110, 1, 0)

MouseClick('Left', $Coords^ ERROR

So the error is in the line that should never occur if the pixel color is not found - but it seems to run it anyway?

I'm guessing that its a very obvious mistake, and I'm just blind. But this has been puzzling me for a good few hours now and driving me nuts.

Any help appreciated,

Naem

Link to comment
Share on other sites

Its checking @error for the pixelsearch function. Apparently @error gets set to 1 if the color isn't found, but I've tried a wide variety of different attempts to avoid this error with no success. Attemps such as:

If Not @error = 1 Then MouseClick('Left', $Coords[0]+50, $Coords[1]+110, 1, 0) EndIf

Or

If @error <> 1 Then MouseClick('Left', $Coords[0]+50, $Coords[1]+110, 1, 0) EndIf

For some reason it will always run the "MouseClick" function, and find that theres no Array since the pixelsearch function didn't find anything.

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