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

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

_Array2D(\$Map1)

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```

Create an account

Register a new account

×

• Wiki