[Closed] How do I create new array names from one array?
I have figured out how to build 4 arrays and I want to create new arrays given the info inside the arrays.
Arrays to Build From
narr = #(bob, jud, bill, mat) – Names are random and the total changes.
farr = #(12f, 120f, 85f, 62f) – Total number of frames active per object above, listed in same order
sarr = #(14f, 18f, 94f, 122f) – First keyed frame (start of motion)
earr = #(26f, 138f, 179f, 184f) – Last keyed frame (end of motion)
New Arrays How?
I want to create one new array for each of the indexed values in “narr” using the values in “narr” to name the new array. This is tricky because the values in “narr” will be unknowns.
Examples:
bob = #(narr[1], farr[1], sarr[1], earr[1]) or bob = #(bob, 12f, 14f, 26f)
jud = #(narr[2], farr[2], sarr[2], earr[2]) or jud = #(jud, 120f, 18f, 138f)
So how do I create new arrays with names based off of the first array when the values inside that array will always be changing?
narr = #("bob", "jud", "bill", "mat")
farr = #(12f, 120f, 85f, 62f)
sarr = #(14f, 18f, 94f, 122f)
earr = #(26f, 138f, 179f, 184f)
-- This will be our new multidimensional array
new_narr = #()
for i = 1 to narr.count do
(
-- Create a new array appending each value of narr one at time
append new_narr narr[i]
-- Create another array for each index of new_narr
-- This will make it a multi dimensional array holding all the relevant values for each element of narr
new_narr[i] = #()
append new_narr[i] farr[i]
append new_narr[i] sarr[i]
append new_narr[i] earr[i]
--print the values using the format command
format "% = %
" narr[i] new_narr[i]
)
hope this helps…
I would use a struct for this. A struct can hold any kind of data you want with any name and it’s much easier to navigate than nested arrays:
struct guy (name, totalFrames, startFrame, endFrame)
bob = guy name:"bob" totalFrames:12f startFrame:14f endFrame:26f
print bob.name
print bob.totalFrames
Or you can build an array of guys (bob, jud, …) and access them individually:
struct guy (name, totalFrames, startFrame, endFrame)
guys = #()
append guys (guy name:"bob" totalFrames:12f startFrame:14f endFrame:26f)
print guys[1].name
something like that.