Kronitron Posted April 2, 2017 Share Posted April 2, 2017 I've been running into issues with arrays. This error seems to be popping up at random. Yesterday I ran a script once and didn't get it. Then I changed some string variable values and got it. I undid these actions and got the error with the version of the script that worked originally. I went to bed baffled, computer off, woke up and tried the script again and it worked. Powering off in and of itself doesn't fix the issue. Here it goes again, in yet another script: "C:\...\Test_4.au3" (17) : ==> Subscript used on non-accessible variable.: $aPixelList[$iCounter] = $aPixFound[0] $aPixelList^ ERROR #include <array.au3> Global $aPixelList Global $aPixFound Global $aCurPix $iXcoordinate = 0 $iYcoordinate = 0 $iCounter = 0 Sleep(4000) Do ;search for pixels matching color 5093208 $aPixFound = PixelSearch($iXcoordinate, $iYcoordinate, 1920,1080, 5093208) ;log any pixels found in an array $aPixelList[$iCounter] = $aPixFound[0] ;error found here $aPixelList[$iCounter + 1] = $aPixFound[1] ;set new starting coordinates for search at the last pixel found was plus one If $aPixFound[0] = 1920 Then $iXcoordinate = 0 $iYcoordinate = $aPixFound[1] + 1 Else $iXcoordinate = $aPixFound[0] + 1 EndIf ;the counter determines which array elements to log pix coordinates to $iCounter += 2 Until @error = 1 ;no more pixels found _ArrayDisplay($aPixelList) ;show me some pixels coordinates! I'm using SciTE Version 3.6.6 and Windows 7 x86. [post='1192322']Detect and Switch Monitor Orientation[/post] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 2, 2017 Moderators Share Posted April 2, 2017 Kronitron, Add some error-checking to your code to confirm you have an array before trying to access it. M23 Kronitron 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Kronitron Posted April 2, 2017 Author Share Posted April 2, 2017 Thank you very much, @Melba23. I tend to be far more thorough in my error-checking but I was errantly confident that nothing could be wrong with the code itself. Logic failed me. I managed to find two parts that needed editing. Declaring and initializing the array with the decimal color code solved one problem and really does great things for the larger script this is all part of. Also, checking that the pixel search found something before proceeding prevented errors as the loop completes its final circuit. Here's what it looks like now: #include <array.au3> $iDecimalColorCode = 5093208 $iXcoordinate = 0 $iYcoordinate = 0 $iCounter = 0 Global $aPixelList[1] = [$iDecimalColorCode] Global $aPixFound Global $aCurPix Sleep(4000) Do $aPixFound = PixelSearch($iXcoordinate, $iYcoordinate, 1920,1080, $iDecimalColorCode) If $aPixFound <> "" Then _ArrayAdd($aPixelList, $aPixFound[0]) _ArrayAdd($aPixelList, $aPixFound[1]) If $aPixFound[0] = 1920 Then $iXcoordinate = 0 $iYcoordinate = $aPixFound[1] + 1 Else $iXcoordinate = $aPixFound[0] + 1 EndIf $iCounter += 2 EndIf Until @error = 1 _ArrayDisplay($aPixelList) [post='1192322']Detect and Switch Monitor Orientation[/post] Link to comment Share on other sites More sharing options...
ripdad Posted April 3, 2017 Share Posted April 3, 2017 Instead of If $aPixFound <> "" Then ...It should be If IsArray($aPixFound) Then ...-Or- If Not @error Then ..From the helpfile PixelSearch Return Value: Success: a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y). Failure: sets the @error flag to 1 if the color is not found. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
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