Pricehacker Posted August 17, 2018 Share Posted August 17, 2018 Hello, Im new to autoit and stumbled uppon an error i could not resolve. Here is the script: #include <AutoItConstants.au3> #include <Misc.au3> AutoItSetOption ( "CaretCoordMode" , 0) AutoItSetOption ( "MouseCoordMode" , 0) AutoItSetOption ( "PixelCoordMode" , 0) AutoItSetOption ( "GUICoordMode" , 0) $aPos = WinGetPos("[ACTIVE]") $aCoord = PixelSearch($aPos[2]*0.654436860068259,$aPos[3]*0.687953555878084,$aPos[2],$aPos[3],15983675) $iVar = 0 If @error = 0 Then if PixelGetColor($aCoord[0],$aCoord[1])<>15983675 Then While PixelGetColor($aCoord[0],$aCoord[1])<>15983675 or @error = 0 or $iVar = 100 $aPos = WinGetPos("[ACTIVE]") $aCoord = PixelSearch($aPos[2]*0.65,$aPos[3]*0.688,$aPos[2],$aPos[3],15983675) $iVar += 1 WEnd Else MouseClick('Left',$aCoord[0],$aCoord[1]) EndIf if @error=1 Then MsgBox(0,'error','color nor found') EndIf if $iVar = 100 Then MouseClick('Left',$aPos[2]*0.870307167235495,$aPos[3]*0.880986937590711) EndIf EndIf Sleep(120000) The full error message i get is: Quote Line 18 (File "C:\Users\Martin\Desktop\auMenu.au3") WEnd WEnd^ ERROR Error: Subscript used in non-accessable variable. Also the reason I have an While loop in the first place is becouse Pixelgetcolor would not (always) work, looping it did however fix this. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 17, 2018 Developers Share Posted August 17, 2018 Only thing i can imagine is that the $aCoord isn't an Array thus the reference to $aCoord[0] and $aCoord[1] on the While statement will fail. Just try to test for $Coord to be an Array with IsArray() before going into the While...Wend loop. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
pixelsearch Posted August 17, 2018 Share Posted August 17, 2018 Hi Pricehacker Jos is certainly right. It seems that your 1st PixelSearch() is successful, it creates a a two-element array of pixel's coordinates $aCoord[0] and $aCoord[1] $aCoord = PixelSearch($aPos[2]*0.654436860068259,$aPos[3]*0.687953555878084,$aPos[2],$aPos[3],15983675) As @error = 0 , then you enter in the While...Wend loop, the While statement executes correctly the 1st time, but now your new PixelSearch during the While...Wend loop isn't successful : $aCoord = PixelSearch($aPos[2]*0.65,$aPos[3]*0.688,$aPos[2],$aPos[3],15983675) It redefines $aCoord to 0, so the Array is gone and your script ends suddenly because there is no more Array, but a simple variable, in the following line : While PixelGetColor($aCoord[0],$aCoord[1])... After you fix this, may I suggest the use of variables for your @error statements, as it's dangerous to test @error in many places of the script because it's easily reset to 0 when any function is called Good luck Link to comment Share on other sites More sharing options...
Pricehacker Posted August 19, 2018 Author Share Posted August 19, 2018 Wow thank you so much for the help both of you! My program works fine now 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