FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   newbie question: an array of objects?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: newbie question: an array of objects?  (Read 335 times)
chevyclutchfoot


newbie question: an array of objects?
« on: Sep 5th, 2003, 11:27am »

I'm not a great coder by any stretch but I'm having fun trying to do this project of mine in processing. Maybe I'm going about this all wrong, but what I'd like to do is create a one-dimensional array in which each unit[] contains several pieces of information. I thought the best way to do this would be to make an object class, and name the objects after the array. That way I can ask for object[3].velocity or whatever. Because I want these objects to be autonomous, and self-generating (though there are to be a fixed number of them) all I need is a way to name an object after a variable.
I've tried converting the variables to char() format, of course to no avail.
It seems the logical way to create ten such objects would be to just be able to say:
 
for (int i = 0; i < 10; i++) {
create c[i] = new crect (random(10), random(10), random(10);
}
 
but even if I go through steps of converting c[i] to a character name and back, processing refuses to use a local variable name to set up an object. So am I screwed, or is there some stupidly easy way of doing this that I'm just missing completely?
 
Any help would be greatly appreciated!
 
Chevy
 
chevyclutchfoot


Re: newbie question: an array of objects?
« Reply #1 on: Sep 5th, 2003, 11:29am »

correction. the object's name is crect (freudian slip)
 
for (int i = 0; i < 10; i++) {  
crect c[i] = new crect (random(10), random(10), random(10);  
}
 
chevyclutchfoot


Re: newbie question: an array of objects?
« Reply #2 on: Sep 5th, 2003, 11:50am »

SORRY ALL - feel free to ignore this.
I just stumbled upon the Module[] mods; example.
I'm not sure what that line of code means, precisely, in english, but I understand what it does...
 
arielm

WWW
Re: newbie question: an array of objects?
« Reply #3 on: Sep 5th, 2003, 11:52am »

not tested, but the following should work:
 
Code:

class Crect // note the use of a capital letter...
{
  Crect(float r1, float r2, float r3)
  {
  }
}
 
Crect[] crect = new Crect[10];
 
for (int i = 0; i < 10; i++)
{
  crect[i] = new Crect(random(10), random(10), random(10));
}

 
--- added just later ---
 
hmm, there should also be a locking system with threads in this forum
« Last Edit: Sep 5th, 2003, 11:54am by arielm »  

Ariel Malka | www.chronotext.org
Pages: 1 

« Previous topic | Next topic »