[Closed] 2D arrays?
Hello
I have an array of objects which i want to add to a 2d array.
can i add a 1d array completly into a row of 2s array?
how do i do it?
here is a sample script which suppose to add the selected objects to a row in a 2d array, is this the right way?
new_stuff = getcurrentselection()
append A[i] new_stuff()
i = i +1
assuming A is an array and new_stuff is any type of value, all you need is
append A new_stuff
the new value is automatically added at the end of the array, no need for an index variable.
A is an array and new_stuff is also an array of objects , i want to add a all of new_stuff array into a single row in 2d array A
lets say i did it twice and i have 4 boxes in the first row of array a and 6 sphares in the second row of array a
how do i choose all objects in a a row in that array?
First create you 2d array, and then you can append new elemtents:
A = #( #(), #() ) -- create array with twoo arrays inside
append A[1] (getcurrentselection()) -- append selected object t first array
append A #() -- you can still grow "root" of arrays
A.count -- will return 3
A[1].count -- will return selected objects count
A[1][3].name -- will return name of 3rd of selected bjects
I hope it explains all.
Hello
Ty for your reply’s i’m still heaving problems
new_stuff is an array of objects which i want to move into a row at undo_objects 2d array
then i would like to delete those objects from scene and from arrays
the 2d array row index will decrease by 1 to be ready for the previus row of objects
what is wrong with this syntax?
append undo_objects [u_level] new_stuff
select undo_objects [u_level]
delete $
delete new_stuff()
delete undo_objects [u_level]
u_level = u_level – 1
append can not insert an item anywhere you tell it, it can only add and items to the end of the array. Use the insertItem method instead.
insertItem <value> <array> <integer>
Inserts the value at the specified index in the array, growing the array if necessary. Returns OK.
I”m trying to create an undo objects for my script.
new_stuff() – array of objects which getting changed every timr i press apply on the script.
i want add all of the new_stuff objects into a row of 2d array called undo_objects.
then i want to select those objects from the undo_objects and delete them from scene and from the 2d array as well.
what am i doing wrong here?
here is the code:
insertitem undo_objects [u_level] new_stuff()
select undo_objects [u_level]
delete $
new_stuff = #()
u_level = u_level – 1
You say new_stuff is an array. So you can’t do call like that new_stuff(). It’s reserved for functions calling.
I’m nt sure you can insert array insideanother. Perhaps you have to insert every element singly, using for loop.
Something like that:
for i=new_stuff.count to 1 by -1 do insertitem undo_objects[u_level] new_stuff[i]
EDIT:
You asked about 2d arrays, so I guess the undo_objects is array of ararays…
In this case you wish to do this:
new_stuff[u_level] = #()
join new_stuff[u_level] new_stuff
undo_objects is an array of arrays which i want to add new_stuff(which is an array of objects)
every time to a diifrent row in undo_objects.
lets say i have 3 boxes in new_stuff
i wan to add those 3 boxes into the first row of undo objects
then i have 3 sphears in new stuff which i want to add to the second row in undo_objects
and so on…
after that i should be able to select a whole row from undo_objects and delete them from scene and from the undo_objects array of arrays.