Simple multi dimensional array problem


#1

Having trouble with this array setup (beginner Copy & Paste programmer).
I keep getting one extra blank line of ‘input’ at the beginning of the array which throws off my index count.
In the example below, I’m accessing position [10] [3] , which should be the value of 109. It keeps coming up 1 value sooner…108.
Hope I explained it well enough…THANKS in advance!

  • Mike

Example:

try(destroyDialog Temp_Array)catch()

– Start Create Rollout Interface
rollout Temp_Array “Temp Array Madness v6” width:260 height:60
(
button ‘Create_Array_MD’ “Create Multi Dim Array” pos:[65,20] height:24 toolTip:“Track selected vertex.” align:#left

on Create_Array_MD pressed do
(
	clearlistener()
	Global Indx = 1  -- Index of an array in Maxscript must start at 1...not 0
	Global Cfrm = 0  -- Temp Frame Number		
	Global Cvtx = 100  -- Temp vertex number
	Global Sfrm = 10  -- starting frame of selection
	Global Efrm = 20  -- ending frame of selection
	Global Lck = "N" -- numbers locked or not
	Global NumItems = 6  --  Number of data items in each 'line' 
	Global AnimRangeStart = 0 -- Starting Frame Number To Process
	Global AnimRangeEnd = 10 -- End Frame Number To Process
	Global myMultiDimArray=#(#(),#()) -- start empty multi dimensional array named 'myMultiDimArray'
	
	sliderTime = 0f
	Indx = 1
	myMultiDimArray=#(#())
	for r = AnimRangeStart to AnimRangeEnd do  -- loop from 0 to total items in range	
	(
		Cfrm = sliderTime as string
		Cfrm = trimright Cfrm "f"
		Cfrm = Cfrm as integer	
		
		Cvtx = 100+Cfrm-- 'get Current Vertex' - changing value here for testing
		
		Sfrm = Sfrm -- get first frame of vertex pos
		Efrm = Efrm -- get last frame when vertex pos	
		
		append myMultiDimArray #(Indx,Cfrm,Cvtx,Sfrm,Efrm,Lck)	

	Indx += 1
	sliderTime += 1
	)	
		print myMultiDimArray
		print "Asking for: myMultiDimArray[10] [3] - Answer should be 109"
		print myMultiDimArray[10] [3]		
)

)
– Create Rollout
createdialog Temp_Array


#2

In addition…here’s what my listener output looks:

#()
#(1, 0, 100, 10, 20, “N”)
#(2, 1, 101, 10, 20, “N”)
#(3, 2, 102, 10, 20, “N”)
#(4, 3, 103, 10, 20, “N”)
#(5, 4, 104, 10, 20, “N”)
#(6, 5, 105, 10, 20, “N”)
#(7, 6, 106, 10, 20, “N”)
#(8, 7, 107, 10, 20, “N”)
#(9, 8, 108, 10, 20, “N”)
#(10, 9, 109, 10, 20, “N”)
#(11, 10, 110, 10, 20, “N”)
“Asking for: myMultiDimArray[10] [3] - Answer should be 109”
Getting - 108 from the previous line


#3

When you created the array, it has one entry with nothing in it. Then you append, which makes your first vertex entry at array[2] instead of array[1]. Haven’t thought of a way around this, but wanted to at least throw out what seems, to me, to be the problem.


#4

Makes sense…
I just created the array after having the first batch of data ready…and it worked!

Thanks for the insight!

Mike


#5

Glad to help :smile: