Jump to content

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


Recommended Posts

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

 

 

 

 

 

 

Link to comment
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

 

Link to comment
Share on other sites

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
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...