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)
   Dynamic Object references
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Dynamic Object references  (Read 758 times)
flight404

WWW Email
Dynamic Object references
« on: Jun 2nd, 2003, 12:37am »

New to programming in any language other than actionscript for Flash (javascript) so please dumb down any answers.  
 
Check the example at
www.flight404.com/p5/worms10
and take a peek at the source.
 
I am making 10 worm objects but in my loop function, I want to be able to refer to the worm objects within a 'for' loop.  Right now, I have to specify that each worm object should execute its movement function like so...
 
w1.move();
w2.move();
w3.move();
etc...
 
What I want is to be able to make this process easier.
 
in actionscript, I would simply...
for (var i=0; i<=totalWorms; i++){
  _root["w" + i].move();
}
 
Is there a proce55ing version of this shortcut?
 
Also, I would like to make dynamic the actual creation of the worm objects.  Right now, I am using 10 lines of code to make 10 worms and that just doesnt seem right.
 
thanks.
robert
 
(i dont know all the lingo so this next part is extra credit because I will undoubtedly have trouble elucidating my problem)
 
I am also having difficulty passing the 'total' variable as a parameter of the object constructor(right term?).  I want to be able to say...
 
Worm w1 = new Worm(100);
 
... and have the worm contain 100 segments.  But unless I hard code the total within the Worm object, it gives me back an "ArrayIndexOutOfBoundsException:1" and though I have some idea of what this error message means, I cannot seem to find my way past it.
« Last Edit: Jun 2nd, 2003, 12:51am by flight404 »  
benelek

35160983516098 WWW Email
Re: Dynamic Object references
« Reply #1 on: Jun 2nd, 2003, 1:25am »

check out the following link to the Learning section; it has an example for how to create and use an array of objects. it should help you with most of your problems... if i missed something, or you'd like more detail, please say so.
http://proce55ing.net/learning/examples/array_objects.html
 
-jacob
 
flight404

WWW Email
Re: Dynamic Object references
« Reply #2 on: Jun 2nd, 2003, 1:51am »

Thanks jacob, that seems to be exactly what I was missing.
 
r
« Last Edit: Jun 2nd, 2003, 1:56am by flight404 »  
Pages: 1 

« Previous topic | Next topic »