Jump to content

Recommended Posts

Posted

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!

Posted (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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Posted

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
Posted

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:

#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
EndFunc

I commneted out the $toggle lines - there is no need for a While...WEnd loop in StartTasks(). :P

Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (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

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 by bnshrdr
  • Moderators
Posted

bnshrdr,

Note anything: ;)

MouseClick("left", $Spot[$i][0], $Spot1[$i][1], 1, 0)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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.

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...