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.
Page Index Toggle Pages: 1
array madness (Read 447 times)
array madness
Jun 11th, 2007, 12:17pm
 
hi, i'm trying to create two classes where the instances of one class are stored inside an array in an instance of the other class. somehow it just doesn't want to work. when i try to append a node or just to expand the array i get an error message but i have no idea why.
i'm new to processing and more familiar with the flash way of coding. please help – i'm close to loosing my sanity!  


here is the nasty code:

CircleMap team1;
Node member1;

void setup(){
 size(400,400);
 noLoop();
 team1 = new CircleMap("some team");
 member1 = new Node("Franz");
 team1.addNode(member1);
}
void draw(){
 background(100);
}
class Node{
 String name;
 Node(String pname){
   name=pname;
 }
}
class CircleMap{
 Node[] circleMapNodes = new Node[0];
 String mapName;
 CircleMap(String name){
   mapName = name;
 }
 void addNode(Node nodeToAdd){
   circleMapNodes = append(circleMapNodes,nodeToAdd); //doesn't work
   //circleMapNodes = expand(circleMapNodes); //doesn't work either
 }
}
Re: array madness
Reply #1 - Jun 11th, 2007, 1:28pm
 
You need to cast the result of append to Node[] as it returns Object[] if it's not a default type.

Code:
circleMapNodes = (Node[])append(circleMapNodes,nodeToAdd); //doesn't work
Re: array madness
Reply #2 - Jun 11th, 2007, 4:18pm
 
thanks, you saved my day!
Page Index Toggle Pages: 1