Jump to content

Array possiblity?


Recommended Posts

I have a 2d array for a map I want to quickly fill the array with data, below is what I tried with no success. Is there anyway of doing this without having to do $Map[0][0] = "x"

$Map[0][1] = "x"

etc..

Global $Map1[31][35]
$Map1[0] = [ "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x" ]
Link to comment
Share on other sites

I made a quick handy function that does the job, it will use a seperator and split x|x|x|x|x|x|x|x into an 1d array then reDim the array and stick it in there.

;~ Global $Map1[31][35]
Global $Map1[1][35]

;~ $Map1[0] = [ "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x" ] 

$Map1 = _Array2DAddRow($Map1, "x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x|x", "|")

_Array2D($Map1)

Func _Array2DAddRow($Arr, $row, $seperator='')
    Local $rows = StringSplit($row, $seperator)
    If UBound($Arr, 2) <= $rows[0] Then
        ReDim $Arr[UBound($Arr,1)+1][$rows[0]]
    Else
        ReDim $Arr[UBound($Arr,1)+1][UBound($Arr,2)]
    EndIf
    $d = UBound($Arr,1)-2
    For $i = 0 To $rows[0] -1 Step 1
        $Arr[$d][$i] = $rows[$i+1]
    Next
    Return $Arr
EndFunc


Func _Array2d ($array, $title="Title")
    If IsArray ( $array ) = 0 Then Return 0
    Local $Buffer
    For $i = 0 To UBound ( $array, 1) -1 Step 1
        For $a = 0 To UBound ( $array, 2) -1  Step 1
            $Buffer &= "[" & $i & "][" & $a & "] = " & $array[$i][$a] & @CRLF
        Next
    Next
    MsgBox ( 1, "Title", $Buffer )
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

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