Count and Save Elements created by mouse click

edited May 2014 in How To...

Hello,

I wrote a code where I create flowers by mouse-click and every third flower is decreasing an augmenting pollution cloud. The code works fine. Now I would like to save how many flowers were created during the game and export the data in an excel or text-file. Could you give me a hide how to do that. Here is my code for the flower function. Thank you.

class Plant {

  float x;
  float y;

  Plant() {
    x = mouseX;
    y = mouseY;

  }

  void display() {
  image(plantita,x,y);
  }
}
 ––––––––––––––––––––––––––––––––––––––––––––––––––

ArrayList plants; // array for plantas
int iP= 0; // iterator plantas

//quantify plants
boolean augment_plant = false;  
int counter_plants = 0;

  boolean plantation() 
  {
   for ( iP = 0; iP < plants.size(); iP++ ) 
      { 
    Plant a = (Plant) plants.get(iP);
    a.display();
      }
  if (mousePressed && (mouseButton == LEFT))
    {
    plants.add(new Plant());
    counter_plants = counter_plants + 1;
    if (counter_plants == 3)
      {
         augment_plant = true;
         counter_plants = 0;
      }
    else 
      {
      augment_plant = false;
      }

     }
    println(augment_plant);
    return augment_plant;
   }

Answers

  • edited May 2014

    plants.size() which you already use is the value you are looking for. See also saveStrings().

    Note that your counter_plants is a redundant counter giving the same value...

Sign In or Register to comment.