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 › Object Array question
Page Index Toggle Pages: 1
Object Array question (Read 395 times)
Object Array question
Mar 16th, 2010, 5:14am
 
Hi,

I am trying to initialise and use an array of an object called Dice, for which I have created the following Class:

class Dice {
 int face;
 float diceX, diceY, diceAngle;
 //constructor
 Dice (int f, float x, float y, float a) {
   this.face = f;
   this.diceX = x;
   this.diceY = y;
   this.diceAngle = a;
 }
 //methods
 public void setFace(int face){
   this.face = face;
 }
 
 public int getFace(int face){
   return face;
 }
 public void setdiceX(float diceX){
   this.diceX = diceX;
 }
 
 public float getdiceX(float diceX){
   return diceX;
 }
 
 public void setdiceY(float diceY){
   this.diceY = diceY;
 }
 
 public float getdiceY(float diceY){
   return diceY;
 }
 
 public void setdiceAngle(float diceAngle){
   this.diceAngle = diceAngle;
 }

 public float getdiceAngle(float diceAngle){
   return diceAngle;
 }
 

 
}

this appears to be fine, but as soon as I call one of the methods, I get an error.

The setup() and a method to debug the code are below, but when run, I get an error "the function getFace() does not exist."

void setup(){
 size(1,1);
 noLoop();
 
 TuioProcessing tuioClient = new TuioProcessing(this);
 
   //get an instance of MidiIO
 midiIO = MidiIO.getInstance(this);
 dice = new Dice[i];
 for (int i=0; i< dice.length; i++) {
   //load dice details into array???
   dice[i] = new Dice(tobj.getSymbolID(), tobj.getX(), tobj.getY(), tobj.getAngle() );
 }
}      


void readDice(Dice[]dice){
 for (int i=0;i< dice.length; i++){
  println(getFace());
 }
}

What am I doing wrong in the Class?

Thanks,
Russell
Re: Object Array question
Reply #1 - Mar 16th, 2010, 6:48am
 
Quote:
dice = new Dice[i];

I don't see where this i comes from. Nor where dice is defined.

Quote:
void readDice(Dice[]dice){
for (int i=0;i< dice.length; i++){
 println(getFace());
}
}

If dice is global, you don't need to pass it as parameter, but that's a detail.
You need to call the method for each instance:
println(dice[i].getFace());
Page Index Toggle Pages: 1