PDA

View Full Version : muilt array problem


jifman
02-12-2008, 01:43 AM
hi people,
sorry im having a silly little problem with setting up a 2d array. i've looked at the exam and examples, but i cant fingure out what im missing.
heres the code and error:


global muiltarray = #(#(),#())

num = 0

for p=1 to 5 do(

for c = 1 to 10 do (

muiltarray[p][c] =num
num=num+1

)--end of P

)--end of C



#(#(), #())
0
-- Error occurred in c loop; filename: D:\Program Files\Autodesk\3ds Max 9\Scripts\array_test.ms; position: 111
-- Frame:
-- c: 1
-- called in p loop; filename: D:\Program Files\Autodesk\3ds Max 9\Scripts\array_test.ms; position: 125
-- Frame:
-- p: 3
-- No ""put"" function for undefined


i can see its creating the 2d array, but it doesnt like it when i try to add things to it in this manor, works fine if i input the data myself.
am i defning the 2d array wrong or something?

Bobo
02-12-2008, 02:29 AM
You cannot have p go higher than 2 because your array contains only 2 sub-arrays. Notice that you crashed at p=3, c=1 which is the first attempt to access the 3rd (non-existent) subarray.
You have to either
*pre-declare the array as #(#(),#(),#(),#(),#()),
*add a line to dynamically add the sub-arrays, or
*limit the outer loop to 2 iterations.

The second approach would look like

muiltarray = #()
num = 0
for p=1 to 5 do(
muiltarray[p]=#() --set the p-th element to an empty array
for c = 1 to 10 do (
muiltarray[p][c] =num --now it is ok to access the p-th element
num=num+1
)--end of P
)--end of C

jifman
02-12-2008, 02:51 AM
cheers for the quick reply bobo,

i think i misunderstood how to define and call a 2d array, becouse what i want to do is to keep the position of thousands of objects over time.
mite it be easier and quicker to use 2 single arrays or 1 2d array?

CGTalk Moderation
02-12-2008, 02:51 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.