Notifications
Clear all

[Closed] Multidimensional Array

I am trying to use an array for importing some vertex points but i can’t figure out how to access the data inside the array in the array.
for example normally i would use

for a = 1 to mesh count do (

Vert_array = #()
Normal_array = #()
UV_array = #()
Face_array = #()

vertcount = readlong f
for b = 1 to vertcount do (
read vertex data here
)
msh = mesh vertices:Vert_array faces:Face_array –build mesh
msh.numTVerts = UV_array.count
buildTVFaces msh
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
for j = 1 to Normal_array.count do setNormal msh j Normal_array[j]
)

now if i put my arrays like Vert_array into a multi dimensional array i get an error if i try
msh = mesh vertices:Vert_array[c] faces:Face_array[c] –build mesh
because it returns the array and not the array contents.

does this make sense any help would be great
i don’t need to use it even if its possible to dynamically create arrays like
vert_array[i] =#()

4 Replies

I am not sure I follow.
How did you create the multi-dimensional arrays?
The example code also has the array definitions inside the FOR A= 1 TO MESHCOUNT loop. They should be outside, and new arrays would have to be collected and appended to them.

Here is a simple example:

Vert_array = #()
Face_array = #()
append Vert_array #([0,0,0],[100,0,0],[100,100,0],[0,100,0])
append Face_array #([1,2,3],[1,3,4])

append Vert_array #([0,0,100],[100,0,100],[100,100,100],[0,100,100])
append Face_array #([1,2,3],[1,3,4])

for c = 1 to Vert_array.count do
(
	msh = mesh vertices:Vert_array[c] faces:Face_array[c] 
)

This creates the two arrays, then appends two new sub-arrays to each one to define two different meshes. Then it loops from 1 to 2 and creates the two meshes using the sub-arrays.

Thanks that was exactly what i wanted to do

one other question say i have
Main_vert_array =#()

for a = 1 to meshcount do (
Temp_array = #()
for i = 1 to vertcount do (
append Temp_array #([0,0,0],[100,0,0],[100,100,0],[0,100,0])
)
append Main_vert_array Temp_array
)
for c = 1 to meshcount do (
print Main_vert_array[c]
)
if i try to access Main_vert_array[c]
i get an array as an output instead of 3 points.
is there a way to get all of the 3 point values from the inner array.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

First of all, the line append Temp_array #([0,0,0],[100,0,0],[100,100,0],[0,100,0]) makes no sense. You are appending 4 vertices in their own array into the subarray that then gets appended to the Main array. You should be appending just one vertex per i loop.
But anyway…

Main_vert_array[c][1] should return the first vertex Point3 value from the first mesh definition. You can access as many levels using the form array[m][n][p][q] as the depth of the multidimensional array allows…