bnshrdr Posted September 19, 2010 Posted September 19, 2010 About 10 years ago I used to program in BASIC-type languages but I have forgotten most of it since I have mostly moved onto C/C++. I'm sure this is some type of syntax error but to me the logic seems at least mostly correct. Here is the code that is producing the error "Array variable subscript badly formatted". The foul is on the line that says: MouseClick("left", $Spot[$i][0], $Spot1[$i][1], 1, 0) Global $Spot[8] GetCoords() Func GetCoords() Local $i For $i = 0 to 7 Step 1 While Not _IsPressed(71) ToolTip("Please hover over the position and hit [F2]!", 0, 0, $Title) $Spot[$i] = MouseGetPos() WEnd Sleep(500) Next StartTasks() EndFunc Func StartTasks() ToolTip("Program Running, press [End] to terminate", 0, 0, $Title) Local $i For $i = 0 to 7 Step 1 While $toggle = 0 MouseClick("left", $Spot[$i][0], $Spot1[$i][1], 1, 0) Opt("MouseClickDownDelay", 200) Sleep(2000) $toggle = 1 MouseClick("left", 308, 875, 1, 0) Opt("MouseClickDownDelay", 200) Sleep(2000) WEnd $toggle = 0 Next Any help will be greatly appreciated!
wakillon Posted September 19, 2010 Posted September 19, 2010 (edited) I see a first error $Spot[$i] = MouseGetPos() MouseGetPos() return an array so may be it's $Spot= MouseGetPos() Or you need to declare a 2 Dimension Array Edited September 19, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
bnshrdr Posted September 19, 2010 Author Posted September 19, 2010 I've tried declaring $Spot like this too: Global $Spot[8][2] But that throws up a different error. To me its not blatantly obvious in this language how to declare, allocate and use multidimensional arrays.
Moderators Melba23 Posted September 19, 2010 Moderators Posted September 19, 2010 bnshrdr,Welcome to the AutoIt forum. Close, but no cigar! You need a bit of revision on arrays. MouseGetPos returns an array - if you save it in another array, you need to extract it before using it. It is easier to put the results directly into the larger array like this:expandcollapse popup#include <Misc.au3> Global $Spot[8][2] ; <<<<<<<<<<<<<<<<< Make this 2D $iOldOpt = Opt("MouseClickDownDelay", 200) ; <<<<<<<<<<<<<<< Always a good idea to reset it later GetCoords() $iOldOpt = Opt("MouseClickDownDelay", $iOldOpt) ; <<<<<<<<<<<<<< Like here Func GetCoords() For $i = 0 To 7 Step 1 ToolTip("Please hover over the position and hit [F2]!", 0, 0," $Title") While Not _IsPressed(71) $aPos = MouseGetPos() $Spot[$i][0] = $aPos[0] ; <<<<<<< Store each element $Spot[$i][1] = $aPos[1] WEnd Sleep(500) Next StartTasks() EndFunc ;==>GetCoords Func StartTasks() ToolTip("Program Running, press [End] to terminate", 0, 0, "$Title") Local $toggle = 0 For $i = 0 To 7 Step 1 ;While $toggle = 0 MouseClick("left", $Spot[$i][0], $Spot[$i][1], 1, 0) ; <<<<<<<<<<< Then you get easy access here Sleep(2000) ;$toggle = 1 MouseClick("left", 308, 875, 1, 0) Sleep(2000) ;WEnd ;$toggle = 0 Next EndFuncI commneted out the $toggle lines - there is no need for a While...WEnd loop in StartTasks(). Please ask if you have any questions. M23 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: Reveal hidden contents 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
AdmiralAlkex Posted September 19, 2010 Posted September 19, 2010 On 9/19/2010 at 6:58 PM, 'bnshrdr said: To me its not blatantly obvious in this language how to declare, allocate and use multidimensional arrays.There's an excellent Array-tutorial in the wiki you may want to look at .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
bnshrdr Posted September 19, 2010 Author Posted September 19, 2010 (edited) @M23 Thanks for the help, it has cleared up that error, but it is still hiccuping on this line MouseClick("left", $Spot[$i][0], $Spot1[$i][1], 1, 0) $Spot1[$i][1] is causing : Variable used without being declared On 9/19/2010 at 7:09 PM, 'AdmiralAlkex said: There's an excellent Array-tutorial in the wiki you may want to look at I read through that and without reading for about 20 minutes I could not find an example similar to mine. I still don't know why this wouldn't work: Global $myArr[8][2] Func MyFunc() For $i = 0 to 7 Step 1 myArr[$i] = MouseGetPos(); This returns an array with 2 elements Next EndFunc Edited September 19, 2010 by bnshrdr
Moderators Melba23 Posted September 19, 2010 Moderators Posted September 19, 2010 bnshrdr,Note anything: MouseClick("left", $Spot[$i][0], $Spot1[$i][1], 1, 0)M23 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: Reveal hidden contents 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
AdmiralAlkex Posted September 19, 2010 Posted September 19, 2010 But you're trying to put an array in an array, there's nothing wrong with that but you have to copy it out before using. An array in an array is nothing like a multi-dimensional array. See the end of the tutorial for a quick discussion about it, but I think it's better to just solve it as Melba showed. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
bnshrdr Posted September 19, 2010 Author Posted September 19, 2010 On 9/19/2010 at 7:19 PM, 'Melba23 said: bnshrdr, Note anything: MouseClick("left", $Spot[$i][0], $Spot1[$i][1], 1, 0) M23 Hah, i guess I didn't notice everything when I translated this over. Thanks.
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