GYJohn Posted March 9, 2016 Posted March 9, 2016 Hello guys, i wrote this code: Spoiler Code expandcollapse popup#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
JohnOne Posted March 9, 2016 Posted March 9, 2016 PixelSearch did not find the colour. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
GYJohn Posted March 9, 2016 Author Posted March 9, 2016 https://www.autoitscript.com/autoit3/docs/functions/PixelSearch.htm What? Why is it the first time working?
AutoBert Posted March 9, 2016 Posted March 9, 2016 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.
InunoTaishou Posted March 9, 2016 Posted March 9, 2016 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
AutoBert Posted March 9, 2016 Posted March 9, 2016 (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 March 9, 2016 by AutoBert
GYJohn Posted March 10, 2016 Author Posted March 10, 2016 I got an idea. I will just close the window, if an error apears. I hope it works. Will repost it later
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now