We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › copying arrays from objects to a new array
Page Index Toggle Pages: 1
copying arrays from objects to a new array (Read 302 times)
copying arrays from objects to a new array
Aug 6th, 2009, 11:35am
 

i have an array of 2 dimensions called objects that store objects, each object has one dimensional array called coords.
I need to copy the contents of all the arrays "coords" that are inside each object into a new array called coords_target.
I was trying to do this in the following way but i got no luck, is there a formula for doing this?




Code:


int al = objects[0][0].coords.length; // con esto cojo el largo de mi array de un objeto


for (int j = 0; j < objects.length; j++)
{
for (int k = 0; k < objects.length; k++)
{
for (int i = 0; i < al; i++)
{
coords_target[ formula?] = objects[j][k].coords[i];
}
}
}
Re: copying arrays from objects to a new array
Reply #1 - Aug 6th, 2009, 12:43pm
 
Why make things complicated.  Doesn't this work?

Code:
int al = objects[0][0].coords.length;  // con esto cojo el largo de mi array de un objeto

int counter = 0;

 for (int j = 0; j < objects.length; j++) {
   for (int k = 0; k < objects.length; k++) {
for (int i = 0; i < al; i++) {
         coords_target[counter] =  objects[j][k].coords[i];
         counter ++;
}
   }
 }

Page Index Toggle Pages: 1