Sign in to follow this  
Followers 0
GYJohn

(16) : ==> Subscript used on non-accessible variable

7 posts in this topic

Hello guys,

i wrote this code:

Spoiler

Code

#include <Array.au3>

HotKeySet("s","start")
HotKeySet("e","ende")

While 1
   Sleep(100)
WEnd

func ende()
   Exit
EndFunc

func sucheButton1()
   $button1 = PixelSearch(800, 400, 1200, 800, 0x9EDD4A)
   $xButton1 =  $button1[0]
   $yButton1 = $button1[1]
   MouseClick("left", $xButton1, $yButton1, 1)
EndFunc

func sucheButton2()
   $button2 = PixelSearch(992, 734, 1082, 811, 0x818283)
   $xButton2 =  $button2[0]
   $yButton2 = $button2[1]
   MouseClick("left", $xButton2, $yButton2, 1)
EndFunc

func start()
   while 1
      If WinActive("[CLASS:ApplicationFrameWindow]") Then
        If Not @error Then
               sucheButton1()
               sleep(3000)
               WinSetState("[CLASS:ApplicationFrameWindow]", "", @SW_MAXIMIZE)
               sleep(3000)
               sucheButton2()
               sleep(1000)
               MouseClick("left", 1899, 15, 1)
               sleep(5000)
        EndIf
    EndIf
wend
EndFunc

On the first 'round' everything is working fine.

After the last sleep(5000) at the start function, the programm is crashing with (16) : ==> Subscript used on non-accessible variable.

I hope you can help me :)

 

Thank you.

 

Greets

John

 

 

 

 

 

 

Share this post


Link to post
Share on other sites



As JohnOne said: Pixelsearch has nothing found, so $Button isn't a array and script crashes when trying to read from array:

$xButton1 = $button1[0]

You have to check the success of Pixelsearch with a If ... Then statement.

Share this post


Link to post
Share on other sites

You could wrap your pixelsearching in a do...until statement. So it will keep trying until it finds it.

; PixelSearch until PixelSearch succeeds
Do
    $button2 = PixelSearch(992, 734, 1082, 811, 0x818283)
Until (Not @Error)

; Or

; PixelSearch until $button2 is an array
Do
    $button2 = PixelSearch(992, 734, 1082, 811, 0x818283)
Until (IsArray($button2))

; Or
; While $button2 is not an array
While (Not IsArray($button2))
    $button2 = PixelSearch(992, 734, 1082, 811, 0x818283)
WEnd

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

1 hour ago, InunoTaishou said:

You could wrap your pixelsearching in a do...until statement. So it will keep trying until it finds it.

And may be waiting for St. Nimmerleinstag (as german says when waiting for something that wouldn't happen). So a TimeOut condition is needed by your method:

; PixelSearch until PixelSearch succeeds or Timedout
$dtStart=TimerInit()
Do
    $button2 = PixelSearch(992, 734, 1082, 811, 0x818283)
Until (Not @Error or (TimerDiff($dtStart)/1000) > 60

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

I got an idea.

I will just close the window, if an error apears.

I hope it works.

Will repost it later :)

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  
Followers 0