AutoIT Subscript used on non accessible Variable

07/06/2020 08:35 ProofPros1#1
Hey elitepvpers,

I tried to create a Script which will Move my Mouse Cursor to the location whenever the color 0xFB9303 is found, then it should wait for the color 0xFFCFC7 to appear, and after that it should click on it as fast as possible.

That seems to work but after a few seconds it crashes with the Crash Code:


Line 20 (File:"File Path, File Name")

Error: Subscript used on non-accessible variable


Heres the Code:

Code:
#RequireAdmin
HotKeySet("g", "start")
HotKeySet("h", "stop")

$WaitColor=0xFB9303
$ClickColor=0xFFCFC7

While 1
    Sleep(100)
WEnd

func stop()
    Exit
EndFunc

func start()
    while 1

      $productbar1 = PixelSearch(850,750,1050,800, $WaitColor,0)
      If Not @error Then
         MouseMove($productbar1[0],$productbar1[1], 1)
      EndIf
      $productbar2 = PixelSearch(850,750,1050,800, $ClickColor,0)
      If Not @error Then
         MouseMove($productbar1[0],$productbar1[1], 0)
         MouseClick("left", $productbar1[0], $productbar1[1]-5, 1, 0)
         Sleep(200)
      EndIf
    WEnd
EndFunc
07/06/2020 17:59 Moneypulation#2
1. check whether the pixel was found with isArray($productbarX). It's better than @error

2.

Code:
$productbar2 = PixelSearch(850,750,1050,800, $ClickColor,0)
      If Not @error Then
         MouseMove($productbar1[0],$productbar1[1], 0)
         MouseClick("left", $productbar1[0], $productbar1[1]-5, 1, 0)
         Sleep(200)
Here, you write the result of PixelSearch in $productbar2 but you try to access $productbar1[0] and [1]. That causes the error