Jump to content

Recommended Posts

Posted (edited)

Can someone please assist or point me in the right direction b/c I am attempting to build a movement tracker an put it in an array and keep getting the following error:

Quote

$Movement[UBound($Movement) + 1][0] = $Movement[UBound($Movement) - 1][0] + 100
^ ERROR

Basically I guess you can say is I am plotting a graph so to speak.

Func Tracking()
    Local $Movement[1][2] = [[0, 0]]
    ConsoleWrite("starting array generation" & @CRLF)
    For $i = 0 To 10
        $Moveto = Random(1, 4, 1)
        Sleep(100)
        If $Moveto = 1 Then
            $Movement[UBound($Movement) + 1][0] = $Movement[UBound($Movement) - 1][0]
            $Movement[UBound($Movement) + 1][1] = $Movement[UBound($Movement) - 1][1] + 100
        ElseIf $Moveto = 2 Then
            $Movement[UBound($Movement) + 1][0] = $Movement[UBound($Movement) - 1][0] + 100
            $Movement[UBound($Movement) + 1][1] = $Movement[UBound($Movement) - 1][1]
        ElseIf $Moveto = 3 Then
            $Movement[UBound($Movement) + 1][0] = $Movement[UBound($Movement) - 1][0]
            $Movement[UBound($Movement) + 1][1] = $Movement[UBound($Movement) - 1][1] - 100
        ElseIf $Moveto = 4 Then
            $Movement[UBound($Movement) + 1][0] = $Movement[UBound($Movement) - 1][0] - 100
            $Movement[UBound($Movement) + 1][1] = $Movement[UBound($Movement) - 1][1]
        EndIf
    Next
    ConsoleWrite("displaying array" & @CRLF)
    _ArrayDisplay($Movement, "Tracking Movement", Default, 1)
EndFunc   ;==>Tracking

 

Edited by Yirrlaar
Posted (edited)

$Movement[UBound($Movement) + 1][0] doesn't exist
You must expand the array before writing data inside, example :

#Include <Array.au3>

Tracking()
Func Tracking()
    Local $Movement[1][2] = [[0, 0]]
    ConsoleWrite("starting array generation" & @CRLF)
    For $i = 0 To 10
        $Moveto = Random(1, 4, 1)
        If $Moveto = 1 Then
           $new = $Movement[$i][0] & "|" & $Movement[$i][1] + 100
        ElseIf $Moveto = 2 Then
           $new = $Movement[$i][0] + 100 & "|" & $Movement[$i][1]
        ElseIf $Moveto = 3 Then
           $new = $Movement[$i][0] & "|" & $Movement[$i][1] -100
        ElseIf $Moveto = 4 Then
           $new = $Movement[$i][0] - 100 & "|" & $Movement[$i][1]
        EndIf
        _ArrayAdd($Movement, $new)
    Next
    ConsoleWrite("displaying array" & @CRLF)
    _ArrayDisplay($Movement, "Tracking Movement", Default, 1)
EndFunc   ;==>Tracking

 

Edited by mikell
Posted
4 hours ago, mikell said:

$Movement[UBound($Movement) + 1][0] doesn't exist
You must expand the array before writing data inside, example :

#Include <Array.au3>

Tracking()
Func Tracking()
    Local $Movement[1][2] = [[0, 0]]
    ConsoleWrite("starting array generation" & @CRLF)
    For $i = 0 To 10
        $Moveto = Random(1, 4, 1)
        If $Moveto = 1 Then
           $new = $Movement[$i][0] & "|" & $Movement[$i][1] + 100
        ElseIf $Moveto = 2 Then
           $new = $Movement[$i][0] + 100 & "|" & $Movement[$i][1]
        ElseIf $Moveto = 3 Then
           $new = $Movement[$i][0] & "|" & $Movement[$i][1] -100
        ElseIf $Moveto = 4 Then
           $new = $Movement[$i][0] - 100 & "|" & $Movement[$i][1]
        EndIf
        _ArrayAdd($Movement, $new)
    Next
    ConsoleWrite("displaying array" & @CRLF)
    _ArrayDisplay($Movement, "Tracking Movement", Default, 1)
EndFunc   ;==>Tracking

 

Thank you so very much!!!

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
×
×
  • Create New...