Sign in to follow this  
Followers 0
Tobei

Problem with 3 dimentional array...

5 posts in this topic

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$locations[$loc_num][1][1] = $MousePos[1]

I'm using the beta version so the MouseGetPos() function can take an argument, which i use to set the current x and y positions into memory...

the idea is pretty simple:

store the current mouse position's pixel color and coordinates in $locations[current location][x/y/c][1]

and then store a 5x5 square of pixel info in the "harvest" area in $locations[current location][x/y/c][2-26]

x or 1 in the code = x coordinate

y or 2 in the code = y coordinate

c or 3 in the code = color in decimal value

I'll past the code in exactly as I wrote it up to now. If you have any experience with multi-dimensional arrays I could really use your help, (i'm fairly new to autoit). Any feedback is welcomed.

Thanks, here it is:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Tobei's Dofus Autoharvester                        http://tobei.atspace.com;
; http://www.dofus.com                                                     ;
; http://www.autoitscript.com                                               ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; What this does:                                                           ;
; Allows user to set harvest locations and mode (1(gather)/2(harvest)       ;
; Runs through set of harvest locations until terminated                     ;
; Checks each location against the original values before clicking.       ;
;  -No more random battles...                                                ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Tobei's Autoharvester v1.0
; Variables -------------------------------------------------------------------
#include <Array.au3>
$filename = "autoharvester.ini"
$user_input = ""
; $locations[location number][x y or c][26 points memorized.]
Dim $locations[1][3][26]
$state = 0
$runs = 0
$loc_num = 0
$var_num = 0
$check_posx = 0
$check_posy = 0
$check_color = 0
$checkfailed = 0
$original_posx = 0
$original_posy = 0
$original_color = 0
$harvest_posx = 0
$harvest_posy = 0
$harvest_color = 0
$harvest_delay = IniRead($filename, "AutoHarvester", "HarvestDelay", 20)
$harvest_option = 1
$harvests = 0
$harvestx = 0
$harvesty = 0
; Hotkeys ---------------------------------------------------------------------
HotKeySet("{ESC}", "interpreter") ;Stop!
HotKeySet("{F1}", "interpreter")  ;Set harvest delay
HotKeySet("{F2}", "interpreter")  ;Set harvest option # (1 or 2)
;Set current mouse pos locations
HotKeySet("{F4}", "interpreter")  ;Go!
; Main Loop -------------------------------------------------------------------
Do
    Sleep(300000);5 minute wait time...
Until 1
; Interpreter -----------------------------------------------------------------
Func interpreter()
    Select
        Case @HotKeyPressed = "{ESC}"
            MsgBox(0, "Tobei's AutoHarvester", "http://tobei.atspace.com")
            Exit
        Case @HotKeyPressed = "{F1}"
            $state = 0
            $user_input = InputBox("Tobei's AutoHarvester Query", _
                    "Please enter your harvest delay in seconds." & @LF & _
                    "Remember to round up.", _
                    IniRead($filename, "AutoHarvester", "HarvestDelay", 20), _
                    "", -1, -1, -1, -1)
            $user_input = Number($user_input)
            $harvest_delay = $user_input
            IniWrite($filename, "AutoHarvester", "HarvestDelay", $user_input)
            Return
        Case @HotKeyPressed = "{F2}"
            $state = 1
            While $state = 1
                $loc_num = $loc_num + 1
                $user_input = MsgBox(0x1024, "Tobei's AutoHarvester Query", _
                        "Do you want to use the first harvest option listed?")
                If $user_input = 7 Then $harvest_option = 2
                If $user_input <> 7 Then $harvest_option = 1
                $user_input = 0
                While $user_input <> 6
                    $mousepos = MouseGetPos()
                    $locations[$loc_num][1][1] = $MousePos[1]
                    $locations[$loc_num][2][1] = $MousePos[2]
                    MouseMove($locations[$loc_num][1][1] - 10, $locations[$loc_num][2][1], 0)
                    $locations[$loc_num][3][1] = PixelGetColor($locations[$loc_num][1][1], $locations[$loc_num][2][1])
                    MouseMove($locations[$loc_num][1][1], $locations[$loc_num][2][1], 0)
                    $user_input = MsgBox(0x1024, "Tobei's AutoHarvester Query", _
                            "Added " & $locations[$loc_num][1][1] & "x" & $locations[$loc_num][2][1] & _
                            " to array at location " & $loc_num & "." & @LF & _
                            "Ensure there are no monsters or players in the regions where you'd click." & @LF & _
                            "When positive, click yes to complete the addition." & @LF & _
                            "If answering No, Autoharvester will read new coords from mouse position.")
                    If $user_input = 7 Then MsgBox(0, "Tobei's AutoHarvester", "Move mouse over position to memorize and press enter.")
                WEnd
                $val_num = 2
                For $x = 1 To 5
                    For $y = 1 To 5
                        $locations[$loc_num][1][$val_num] = (($locations[$loc_num][1][$val_num] + 12) + $x)
                        $locations[$loc_num][2][$val_num] = (($locations[$loc_num][2][$val_num] + (22 * $harvest_option)) + $y)
                        $locations[$loc_num][3][$val_num] = PixelGetColor($locations[$loc_num][1][$val_num], $locations[$loc_num][2][$val_num])
                        Add("$val_num", 1)
                    Next
                Next
                $val_num = 1
                $user_input = MsgBox(0x1024, "Tobei's AutoHarvester", "Would you like to add another location?")
                If $user_input = 6 Then
                    ReDim $locations[$loc_num + 1][3][26]
                    MsgBox(0x1020, "Tobei's AutoHarvester", "Place mouse over position and press enter.")
                    ContinueLoop
                Else
                    $state = 0
                    Return
                EndIf
            WEnd
            Return
        Case @HotKeyPressed = "{F4}"
            $loc_num = 1
            $val_num = 1
            $runs = 0
            $state = 2
            While $state = 2
                $runs = $runs + 1
                For $loc_num = 1 To UBound($locations, 1)
                    For $val_num = 1 To UBound($locations, 3)
                        $check_posx = $locations[$loc_num][1][$val_num]
                        $check_posy = $locations[$loc_num][2][$val_num]
                        $check_color = $locations[$loc_num][3][$val_num]
                        If check_location($check_posx, $check_posy, $check_color) <> 1 Then
                            $checkfailed = 1
                            If $val_num = 1 Then
                                ExitLoop
                            EndIf
                        Else
                            $checkfailed = 0
                            If $val_num > 1 Then
                                $harvest_posx = $locations[$loc_num][1][$val_num]
                                $harvest_posy = $locations[$loc_num][2][$val_num]
                                ExitLoop
                            Else
                                $original_posx = $locations[$loc_num][1][$val_num]
                                $original_posy = $locations[$loc_num][2][$val_num]
                                $original_color = $locations[$loc_num][3][$val_num]
                            EndIf
                        EndIf
                    Next
                    If $checkfailed = 1 Then ContinueLoop
                    perform_harvest($original_posx, $original_posy, $harvest_posx, $harvest_posy)
                    update_tip()
                Next
            WEnd
            Return
    EndSelect
EndFunc  ;==>interpreter
; Functions -------------------------------------------------------------------
; Click on $x, $y then Click on $harvestx, $harvesty then Click on 250, 470
; Delay for $harvest_delay + 5% then add 1 to $harvests
Func perform_harvest($x, $y, $harvestx, $harvesty)
    MouseClick("Left", $x, $y, 1, 3)
    MouseClick("Left", $harvest_posx, $harvest_posy, 1, 4)
    MouseClick("Left", 250, 470, 1, 2)
    Sleep(($harvest_delay * 1050))
    $harvests = $harvests + 1
    Return
EndFunc  ;==>perform_harvest
; Update tooltip
Func update_tip()
    $buf = "Autoharvesting from " & UBound($locations, 1) & " locations at " & $harvest_delay & " second intervals..." & @LF
    If $harvest_option = 2 Then $buf = $buf & "Using second harvest option.  "
    $buf = $buf & "Just harvested location " & $loc_num & "." & @LF
    $buf = $buf & "Runs completed: " & $runs & "." & @LF
    $buf = $buf & "Harvests so far: " & $harvests & "." & @LF
    ToolTip($buf, 558, 523, "Tobei's Autoharvester", 1, 2)
EndFunc  ;==>update_tip 
; Returns 1 if color $c is equal to current color at $x, $y & moves mouse there
Func check_location($x, $y, $c)
    MouseMove(250, 470, 2)
    If PixelGetColor($x, $y) = $c Then
        MouseMove($x, $y, 2)
        Return (1)
    Else
        return (0)
    EndIf
EndFunc  ;==>check_location
; Sets $arg1 = $arg1 + $arg2
Func Add($arg1, $arg2)
    Eval($arg1 = $arg1 + $arg2)
    Return
EndFunc  ;==>Add

Share this post


Link to post
Share on other sites



What is the $loc_num value when you get the error ?

it would be 1

i don't know how to verify that...

Share this post


Link to post
Share on other sites

well, just have it write the value to a file everytime it's set, or maybe adlibenable a function that constantly copies the value to clipboard would work too...


[quote]If whenever you feel small, useless, offended, depressed, and just generally upset always remember......you were once the fastest and most vicious sperm out of hundreds of millions![/quote]

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