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 › sending arrays to objects
Page Index Toggle Pages: 1
sending arrays to objects (Read 735 times)
sending arrays to objects
Aug 24th, 2009, 3:03am
 
Hi , is it possible to send an array to an object? i have an array in my main program and i want to send that array to an object, is it posible to send the complete array as an argument for the object? or do i need to send each value of my array independently?

thanks


Mateo
Re: sending arrays to objects
Reply #1 - Aug 24th, 2009, 3:36am
 
Yes:

Code:
int[] myArray = {1,2,3,4,5,6,7,8,9};
// pass the array as a constructor argument
arrayIterator foo = new arrayIterator(myArray);


void setup() {
   size(10,10);
   foo.iterateArray();
}

///////////////////////////////////////////
class arrayIterator {
 int[] theArray;
 
 // constructor
 arrayIterator(int[] inputArray) {
   this.theArray = inputArray;  
 }

 // method
 void  iterateArray() {
   for(int i=0; i<theArray.length; i++) {
     println(theArray[i]);
   }  
 }
   
}
Re: sending arrays to objects
Reply #2 - Aug 25th, 2009, 7:24am
 
cool , but my question was about sending a changing array. My array has fft data that i would like to send to an object not just when i create the object but all the time because the fft array is changing the values all the time. Is it possible? Can i send an array as an argument for an objects method?

thanks
Re: sending arrays to objects
Reply #3 - Aug 26th, 2009, 6:43am
 
Actually, if you change the data in the array, the object will see the new data: it stored actually a reference to the array, not the data itself.
Page Index Toggle Pages: 1