tom13 Posted May 24, 2008 Share Posted May 24, 2008 Hi there, I have a function that returns multiple coordinates with a 2 dimensional array, eg.: $array[0][0] = 123, 423 $array[1][1] = 1214, 12312 $array[2][2] = 2344, 1231 Just some random numbers.. I hope you understand what I mean (i'm not sure how 2 dimensional arrays work, and the help file didn't really help me). So, now I want to know how I receive 12312.. should I do this like this? $array[1][1] ? Because I tried that but got an error.. Using it in this script but getting an error when the pixel that is being looked for is (temporarily) invisible.. also I noticed $i going higher then UBound($check), even though that should not be possible in my script? expandcollapse popup#Include <Misc.au3> #Include <Array.au3> ;Receive mini-map coordinates (left) MsgBox(64 + 0, "Mini-map coordinates", "Please click on the TOP LEFT corner of the minimap.") Do Sleep(1) Until _IsPressed("01") $minimapcoordleft_x = MouseGetPos(0) $minimapcoordleft_y = MouseGetPos(1) ;Receive mini-map coordinates (right) MsgBox(64 + 0, "Mini-map coordinates", "Please click on the BOTTOM RIGHT corner of the minimap.") Do Sleep(1) Until _IsPressed("01") $minimapcoordright_x = MouseGetPos(0) $minimapcoordright_y = MouseGetPos(1) MsgBox(0, "", "Left click top left corner of waypoint.") Do Sleep(1) Until _IsPressed("01") $waypointleftx = MouseGetPos(0) $waypointlefty = MouseGetPos(1) MsgBox(0, "", "Left click bottom right corner of waypoint.") Do Sleep(1) Until _IsPressed("01") $waypointrightx = MouseGetPos(0) $waypointrighty = MouseGetPos(1) $pixlt = PixelGetColor($waypointleftx, $waypointlefty) $pixlb = PixelGetColor($waypointleftx, $waypointrighty) $pixrt = PixelGetColor($waypointrightx, $waypointlefty) $pixrb = PixelGetColor($waypointrightx, $waypointrighty) $width = $waypointrightx - $waypointleftx $height = $waypointrighty - $waypointlefty $playerarrowx = $minimapcoordleft_x + (($minimapcoordright_x - $minimapcoordleft_x) / 2) $playerarrowy = $minimapcoordleft_y + (($minimapcoordright_y - $minimapcoordleft_y) / 2) While 1 $i = 0 $Match = False $check = _PixelSearchEx($minimapcoordleft_x, $minimapcoordleft_y, $minimapcoordright_x, $minimapcoordright_y, $pixlt) If IsArray($check) Then $matches = UBound($check) Do If PixelGetColor($check[$i][0] + $width, $check[$i][$i]) = $pixrt AND PixelGetColor($check[$i][0], $check[$i][$i] + $height) = $pixlb AND PixelGetColor($check[$i][0] + $width, $check[$i][$i] + $height) = $pixrb Then $Match = True $lastx = $check[$i][0] + ($width / 2) $lasty = $check[$i][$i] + ($height / 2) $i = 0 ElseIf $i < UBound($check, 1) Then $i += 1 Else $i = 0 EndIf Until $Match = True OR $i >= $matches If _IsPressed("11") Then If $lastx > $playerarrowx Then $px1 = $lastx - $playerarrowx $dir1 = "east" ElseIf $lastx < $playerarrowx Then $px1 = $playerarrowx - $lastx $dir1 = "west" ElseIf $lastx = $playerarrowx Then $px1 = 0 $dir1 = "ahead" EndIf If $lasty > $playerarrowy Then $px2 = $lasty - $playerarrowy $dir2 = "north" ElseIf $lasty < $playerarrowy Then $px2 = $playerarrowy - $lasty $dir2 = "north" ElseIf $lasty = $playerarrowy Then $px2 = 0 $dir = "ahead" EndIf MsgBox(0, "direction", "you have to go: " & $px1 & " pixels " & $dir1 & " and " & $px2 & " pixels " & $dir2) EndIf EndIf WEnd Func _PixelSearchEx($xTop, $yTop, $xBottom, $yBottom, $nColor, $iShade = 0, $iStep = 1) Local $aPix, $aCoords, $nYAdd, $iAdd For $xCC = $xTop To $xBottom $nYAdd = 0 While $nYAdd <= $yBottom $aPix = PixelSearch($xCC, $yTop + $nYAdd, $xCC, $yBottom, $nColor, $iShade, $iStep) If Not IsArray($aPix) Then ExitLoop If Not IsArray($aCoords) Then Local $aCoords[1][2] $nYAdd += ($aPix[1] - $yTop) + 1 $iAdd += 1 ReDim $aCoords[$iAdd + 1][2] $aCoords[$iAdd][0] = $aPix[0] $aCoords[$iAdd][1] = $aPix[1] WEnd Next If IsArray($aCoords) Then Return $aCoords Return SetError(1, 0, 0) EndFunc >"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\...\test1.au3" C:\...\test1.au3 (50) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: If PixelGetColor($check[$i][0] + $width, $check[$i][$i]) = $pixrt AND PixelGetColor($check[$i][0], $check[$i][$i] + $height) = $pixlb AND PixelGetColor($check[$i][0] + $width, $check[$i][$i] + $height) = $pixrb Then If PixelGetColor($check[$i][0] + $width, ^ ERROR >Exit code: 1 Time: 16.465 Link to comment Share on other sites More sharing options...
weaponx Posted May 25, 2008 Share Posted May 25, 2008 This is ugly code and it takes twice as long to fetch: $minimapcoordleft_x = MouseGetPos(0) $minimapcoordleft_y = MouseGetPos(1) Do this instead: $minimapcoordleft = MouseGetPos() This way X is in element [0] and Y is in element [1] Link to comment Share on other sites More sharing options...
tom13 Posted May 25, 2008 Author Share Posted May 25, 2008 This is ugly code and it takes twice as long to fetch: $minimapcoordleft_x = MouseGetPos(0) $minimapcoordleft_y = MouseGetPos(1) Do this instead: $minimapcoordleft = MouseGetPos() This way X is in element [0] and Y is in element [1] Okay.. but what about my real problem? This does not solve it of course. Link to comment Share on other sites More sharing options...
tom13 Posted May 25, 2008 Author Share Posted May 25, 2008 (edited) Okay.. but what about my real problem? This does not solve it of course. Ok, I made a log and apparently $i is becoming higher then the actual numbers of Ubound($check) when the PixelSearch function fails to find the pixel. 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:49 : 0 2008-05-25 10:26:49 : 1 2008-05-25 10:26:49 : 0 2008-05-25 10:26:49 : 1 2008-05-25 10:26:49 : 0 2008-05-25 10:26:49 : 1 2008-05-25 10:26:49 : 2 This is where it crashes. Does anyone understand however why $i becomes higher then UBound($check) ? I made a check for this so it should not happen right? [EDIT] Oh, apparently it is not. UBound is getting higher when it crashed, see new log file where UBound is the second value (after -): 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:02 : 0 - 2 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:02 : 0 - 2 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:02 : 0 - 2 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 3 2008-05-25 10:31:03 : 1 - 3 2008-05-25 10:31:03 : 2 - 3 So how come it goes wrong here? Edited May 25, 2008 by tom13 Link to comment Share on other sites More sharing options...
martin Posted May 25, 2008 Share Posted May 25, 2008 Ok, I made a log and apparently $i is becoming higher then the actual numbers of Ubound($check) when the PixelSearch function fails to find the pixel. 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:48 : 0 2008-05-25 10:26:48 : 1 2008-05-25 10:26:49 : 0 2008-05-25 10:26:49 : 1 2008-05-25 10:26:49 : 0 2008-05-25 10:26:49 : 1 2008-05-25 10:26:49 : 0 2008-05-25 10:26:49 : 1 2008-05-25 10:26:49 : 2 This is where it crashes. Does anyone understand however why $i becomes higher then UBound($check) ? I made a check for this so it should not happen right? [EDIT] Oh, apparently it is not. UBound is getting higher when it crashed, see new log file where UBound is the second value (after -): 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:02 : 0 - 2 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:02 : 0 - 2 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:02 : 0 - 2 2008-05-25 10:31:02 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 2 2008-05-25 10:31:03 : 1 - 2 2008-05-25 10:31:03 : 0 - 3 2008-05-25 10:31:03 : 1 - 3 2008-05-25 10:31:03 : 2 - 3 So how come it goes wrong here?UBound returns the number of elements. If you have 10 elements then the elements are [0],[1],..[9] SO you must not let $i go higher than Ubound - 1. I think you need to change this ElseIf $i < UBound($check, 1) Then $i += 1 to ElseIf $i < UBound($check, 1) -1 Then $i += 1 Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
tom13 Posted May 25, 2008 Author Share Posted May 25, 2008 UBound returns the number of elements. If you have 10 elements then the elements are [0],[1],..[9] SO you must not let $i go higher than Ubound - 1. I think you need to change this ElseIf $i < UBound($check, 1) Then $i += 1 to ElseIf $i < UBound($check, 1) -1 Then $i += 1 Thanks for the reply, however it does not work. I still get this error: >"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\...\test2.au3" C:\...\test2.au3 (50) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: If PixelGetColor($check[$i][0] + $width, $check[$i][$i]) = $pixrt AND PixelGetColor($check[$i][0], $check[$i][$i] + $height) = $pixlb AND PixelGetColor($check[$i][0] + $width, $check[$i][$i] + $height) = $pixrb Then If PixelGetColor($check[$i][0] + $width, ^ ERROR >Exit code: 1 Time: 28.007 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