Jump to content
Sign in to follow this  

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"


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" ]

Share this post

Link to post
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", "|")


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]]
        ReDim $Arr[UBound($Arr,1)+1][UBound($Arr,2)]
    $d = UBound($Arr,1)-2
    For $i = 0 To $rows[0] -1 Step 1
        $Arr[$d][$i] = $rows[$i+1]
    Return $Arr

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
    MsgBox ( 1, "Title", $Buffer )

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.