Sign in to follow this  
Followers 0
meowbits

ERROR: Subscript used with non-Array variable.:

21 posts in this topic

I get the error, its located here at the start of the script box.

Anyone know what I can do to solve it?

Func _start()
     $Colors = IniReadSection($Gloc & $Ginfo & ".ini", "Colors")
     For $i = 0 To $Colors[0][0]
         $data[$i] = IniRead($Gloc & $Ginfo & ".ini", "Colors", $i, "")
         If $i >= 10 Then ExitLoop
     Next
     $pause = Not $pause
     While $pause
         ToolTip('GameBot is "Running"..   Press F9 to Quit', 0, 0)
         $t = 0
         Do
             $t = $t + 1
             If $t > 10 Then ExitLoop
             Sleep($cwait)
         Until Not @error
         If $t > 10 Then ContinueLoop
         MouseClick("left", $Cpos[0], $Cpos[1], 1, 0)
;MouseMove($left, $top)
     WEnd
     ToolTip('')
     GUISetState(@SW_RESTORE, $Gamebot)
     HotKeySet("{F9}")
EndFunc;==>_start

Share this post


Link to post
Share on other sites



You haven't provided enough code.

Share this post


Link to post
Share on other sites

All of it =-)

Opt("WinWaitDelay",3000)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Dim $pos = "", $CHex = "", $Cpos = "", $Count = 0, $data[11], $Label_[11], $Run, $Launcher, $cwait = 0
Dim $pause, $left = 0, $right = 0, $top = 0, $bottom = 0
Dim $Gloc = @ScriptDir & "\Games\", $Ginfo

Opt("PixelCoordMode", 0)   ;1=absolute, 0=relative, 2=client
Opt("MouseCoordMode", 0)   ;1=absolute, 0=relative, 2=client

HotKeySet("{ESC}", "Terminate")

$Gamebot = GUICreate("Min. PRIOR to pressing F9", 260, 155, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_CHECKED)
$Group_10 = GUICtrlCreateGroup("Pixel Search Area", 10, 5, 240, 95)
$Label_11 = GUICtrlCreateLabel("Left              Top             Right        Bottom", 20, 25, 350, 20)
$Input_12 = GUICtrlCreateInput($left, 20, 45, 40, 20)
$Input_13 = GUICtrlCreateInput($top, 80, 45, 40, 20)
$Input_14 = GUICtrlCreateInput($right, 140, 45, 40, 20)
$Input_15 = GUICtrlCreateInput($bottom, 200, 45, 40, 20)
$Button_29 = GUICtrlCreateButton("Get Area", 86, 68, 90, 25)
$Button_33 = GUICtrlCreateButton("Run FarmBot", 12, 115, 110, 30)
$Button_34 = GUICtrlCreateButton("Exit FarmBot", 135, 115, 110, 30)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_34
            ExitLoop
        Case $msg = $Button_29
            Get_Area()
        Case $msg = $Button_33
             Set_Run()


; pixel search
     $left = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Left", "None")
     GUICtrlSetData($Input_12, $left)
     $top = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Top", "None")
     GUICtrlSetData($Input_13, $top)
     $right = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Right", "None")
     GUICtrlSetData($Input_14, $right)
     $bottom = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Bottom", "None")
     GUICtrlSetData($Input_15, $bottom)
     $Vary = IniRead($Gloc & $Ginfo & ".ini", "Settings", "Vary", "5")
    EndSelect
WEnd

Func Get_Area()
     $Count = 0
     If GUICtrlRead($Button_29) = "Get Area" Then
         HotKeySet("{F9}", "set_Area")
         ToolTip('Press "F9" to Get the Area under the Mouse Left-Top-Right-Bottom, Click "Done" when Finished', 0, 0)
         GUICtrlSetData($Button_29, "Done")
         Return
     Else
         HotKeySet("{F9}")
         ToolTip('')
         GUICtrlSetData($Button_29, "Get Area")
         MsgBox(0,"Test",$left & @LF & $top & @LF & $right & @LF & $bottom)
         $Count = 0
     EndIf
EndFunc;==>Get_Area

Func set_Area()
     $Count = $Count + 1
     $Mpos = MouseGetPos()
     If $Count = 1 Then GUICtrlSetData($Input_12, $Mpos[0])
     If $Count = 2 Then GUICtrlSetData($Input_13, $Mpos[1])
     If $Count = 3 Then GUICtrlSetData($Input_14, $Mpos[0])
     If $Count = 4 Then GUICtrlSetData($Input_15, $Mpos[1])
     If $Count >= 4 Then $Count = 0
EndFunc;==>set_Area
 
Func Set_Run()
    If $Run = 1 Then
        Run(@ComSpec & " /c Start " & $Launcher, "", @SW_HIDE)
        $ON = True
    ElseIf $Run = 2 Then
        $Launched = FileGetShortName($Launcher)
        Run(@ComSpec & " /c Start " & $Launched, "", @SW_HIDE)
        $ON = True
    EndIf
    GUISetState(@SW_MINIMIZE, $Gamebot)
    ToolTip('Press F9 to Start Game', 0, 0)
    _ReduceMemory()
    HotKeySet("{F9}", "_start")
EndFunc;==>Set_Run


Func _start()
     $Colors = IniReadSection($Gloc & $Ginfo & ".ini", "Colors")
     For $i = 0 To $Colors[0][0]
         $data[$i] = IniRead($Gloc & $Ginfo & ".ini", "Colors", $i, "")
         If $i >= 10 Then ExitLoop
     Next
     $pause = Not $pause
     While $pause
         ToolTip('GameBot is "Running"..   Press F9 to Quit', 0, 0)
         $t = 0
         Do
             $t = $t + 1
             If $t > 10 Then ExitLoop
             Sleep($cwait)
         Until Not @error
         If $t > 10 Then ContinueLoop
         MouseClick("left", $Cpos[0], $Cpos[1], 1, 0)
;MouseMove($left, $top)
     WEnd
     ToolTip('')
     GUISetState(@SW_RESTORE, $Gamebot)
     HotKeySet("{F9}")
EndFunc;==>_start

Func _ReduceMemory()
     Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
     Return $ai_Return[0]
EndFunc;==>_ReduceMemory

Func Terminate()
     Exit
EndFunc;==>Terminate




; declare variable color (use Eyedropper4.0 to find color,
; keep 0x and add your 6 digit number after it)

;Dim $left, $top, $right, $bottom

Global $storeIconColor = 0xB0BD62 ; store icon color 
Global $hayBailColor = 0xF7A505 ; haybail color
Global $grassColor = 0x3A7A02   ; grass color

Global $bailsTobuy      ; Number of haybails to buy/sell
Global $storeCoords     ; Coordinates of the store icon
Global $otherCoords     ; Coordinates of the 'other' tab
Global $buyHayBailCoords ; Coordinates to buy haybail
Global $placeHayBailCoords ; Coordinates to place haybail
Global $sellHayBailCoords = $placeHayBailCoords
Global $confirmSellCoords; Coordinates to sell haybail (final)
Global $clickSellCoords ; Coordinates to click 'sell'

Global $storeCoords[2]        ; Coordinates of the store icon
Global $otherCoords[2]        ; Coordinates of the 
Global $buyHayBailCoords[2]  ; Coordinates of the 
Global $placeHayBailCoords[2]   ; Coordinates of the 
Global $ssellHayBailCoords[2]   ; Coordinates of the 
Global $confirmCoords[2]        ; Coordinates of the 

; declare ON true(on) false(off)
Global $ON

;If $bailsTobuy != Int Then
; dialog box to prompt for total bails to buy/sell - NEED HELP
; Amount of bails you can afford is ((Total Coins -50)/48)) round down
; if answer != integer stop or run a loop to ask again, not sure how to.
; answer = $baysToBuy

;If ($CmdLine[0] = 2) Then
;Exit 0
;EndIf

     $left = GUICtrlRead($Input_12)
     $top = GUICtrlRead($Input_13)
     $right = GUICtrlRead($Input_14)
     $bottom = GUICtrlRead($Input_15)


;If ($CmdLine[0] = 1) Then 
;If $ON = True Then
; Open url to play FarmTown
; _IECreate ("http://apps.facebook.com/farmtown/play/", 1, 1, 1, 1)
; Initial loop
    Dim $iCounter = 1
    While $iCounter = 1
    Sleep(500)
        if $ON = True Then
            ; click store icon
                $storeCoords[0] = Round(($right - $left)*(77.63/100), 0) + $left
                $storeCoords[1] = Round(($bottom - $top)*(91.37/100), 0) + $top
                MouseClick("left", $storeCoords[0], $storeCoords[1])
            Sleep(300)
            ; save coords as 'otherCoords'
                $otherCoords[0] = Round(($right - $left)*(81.57/100), 0) + $left
                $otherCoords[1] = Round(($bottom - $top)*(15.51/100), 0) + $top
                MouseClick("left", $otherCoords[0], $otherCoords[1])
            Sleep(300)
            ; save coords as 'buyHayBailCoords'
                $buyHayBailCoords[0] = Round(($right - $left)*(30.26/100), 0) + $left
                $buyHayBailCoords[1] = Round(($bottom - $top)*(32.75/100), 0) + $top
                MouseClick("left", $buyHayBailCoords[0], $buyHayBailCoords[1])
            Sleep(300)
        ; click grass
            ; save coords as 'placeHayBailCoords'
                $placeHayBailCoords[0] = Round(($right - $left)*(38/100), 0) + $left
                $placeHayBailCoords[1] = Round(($bottom - $top)*(39/100), 0) + $top
                MouseClick("left", $placeHayBailCoords[0], $placeHayBailCoords[1])
                Sleep(300)
            ; click haybail just placed (samespot)
                MouseClick("left", $sellHayBailCoords[0], $sellHayBailCoords[1])
            Sleep(300)
            ; save coords as 'confirmSellCoords'
                $clickSellCoords[0] = Round(($right - $left)*(37.5/100), 0) + $left
                $clickSellCoords[1] = Round(($bottom - $top)*(42.25/100), 0) + $top
                MouseClick("left", $clickSellCoords[0], $clickSellCoords[1])
            Sleep(300)
            ; save coords as 'clickSellCoords'
                $confirmSellCoords[0] = Round(($right - $left)*(42.1/100), 0) + $left
                $confirmSellCoords[1] = Round(($bottom - $top)*(53.44/100), 0) + $top
                MouseClick("left", $confirmSellCoords[0], $confirmSellCoords[1])
        EndIf
        $iCounter +=1
    WEnd
    
    Dim $bCounter = 1
; Main loop
    While $bailsTobuy -1 >= $bCounter
        Sleep(5000)
        MouseClick("left", $storeCoords[0], $storeCoords[1])
        Sleep(300)
        MouseClick("left", $buyHayBailCoords[0], $buyHayBailCoords[1])
        Sleep(300)
        MouseClick("left", $placeHayBailCoords[0], $placeHayBailCoords[1])
        Sleep(300)
        MouseClick("left", $sellHayBailCoords[0], $sellHayBailCoords[1])
        Sleep(300)
        MouseClick("left", $clickSellCoords[0], $clickSellCoords[1])
        Sleep(300)
        MouseClick("left", $confirmSellCoords[0], $storeCoords[1])
        $bCounter +=1
    WEnd
;EndIf

Share this post


Link to post
Share on other sites

Check for @error after IniReadSection in the _start function. It's possible that your INI file doesn't have the section you requested.

Share this post


Link to post
Share on other sites

I dont even want an ini file =-( I just want to have the user pick dimensions, use those dimensions to determine where to click.

And loop it. =-/

Share this post


Link to post
Share on other sites

You might want to assign a value to $Ginfo somewhere in your code ...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I suggest running two threads on the same code is not a good idea – mods don’t like it. The use of the autoit code greatly increases readability in the code you posted.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Two different problems completely. He just said I didn't show enough of the code. Am I suppose to make one with a whole bunch of problems?

Share this post


Link to post
Share on other sites

I'll say it again. YOU'RE NOT SETTING UP $Ginfo IN YOUR CODE.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Two different problems completely. He just said I didn't show enough of the code. Am I suppose to make one with a whole bunch of problems?

mate - do whatever u feel is best.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

#11 ·  Posted

Hey good catch WBD. I didn't even notice that. The problem I mentioned was related to the one you found though. XD

Share this post


Link to post
Share on other sites

#12 ·  Posted

Hmm, how do I use that? I didn't see a whole lot in the help guide. =-/

Share this post


Link to post
Share on other sites

#13 ·  Posted

Be more specific. How do you use which?

Share this post


Link to post
Share on other sites

#14 ·  Posted

The $Ginfo, I dont understand how it works, or how to call it.

Share this post


Link to post
Share on other sites

#15 ·  Posted

It's a variable. You set values to variables.

You pretty much just admitted you didn't write this script though.

Share this post


Link to post
Share on other sites

#16 ·  Posted

I didn't write the whole thing. Mine starts at the Global variable declaration, why does it even matter? Lol.

Share this post


Link to post
Share on other sites

#17 ·  Posted

You don't understand what it's doing. That's why it matters.

Share this post


Link to post
Share on other sites

#18 ·  Posted

Thats why I was asking what was wrong with it lol.

Share this post


Link to post
Share on other sites

#19 ·  Posted

You should be learning the basics of the language instead. You didn't even know what to do with a variable.

Share this post


Link to post
Share on other sites

#20 ·  Posted

I do know what to do with variables, I didn't realize THAT was a variable. Anyway.. thanks for your help? I guess... lol. You spend enough time going back and forth about it instead of actually demonstrating your badass skills.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0