int foodNum = 50; //How much food is created initially
int foodInterval = 3000; //The at which food is created after the start
int initialOrganismNum = 10; //How many organisms are initially created
int startingEnergyLevel = 100; //The energy each organism starts with
int i = 0;
ArrayList food;
//ArrayList organism;
void setup() {
size(700,500);
food = new ArrayList(foodNum);
while (i < foodNum) {
food.add(new Food(15,10));
i++;
}
foodNum = food.size();
i = 0;
while (i < foodNum) {
Food foodie = (Food) food.get(i);
foodie.place();
foodie.display();
i++;
}
}
void draw() {
background(255);
foodNum = food.size();
i = 0;
while (i < foodNum) {
Food foodie = (Food) food.get(i);
foodie.display();
i++;
}
}
class Food() {
int x;
int y;
int r;
int energy;
Food (int rad, int ie) {
r = rad;
energy = ie;
}
void place() {
x = random(r, width-r);
y = random(r, height-r);
}
void display() {
ellipse(x,y,r*2,r*2);
}
}
It is the beginning of a natural selection simulator I am writing. I am sure there is just something stupid that I have done wrong, but it always returns this error:
Unexpected token: (
and highlights the curly bracket on line 33 of the above code. I triple checked everything to see if I could see any missing semicolons or other basic "grammatical" issues but couldn't find anything. I'm sure it's something stupid as this code doesn't do much of anything yet.
I am sure that this is a very simple problem to solve, but I have been baffled by it. I want to create instances of a class using a while loop, because I want the number of objects to depend on a different input number every time. I want each instance to have a different name, and it would be simplest if the name was "variable" plus the number it is in the while cycle. (For example, if it was the 3rd instance, variable3) The problem is that I don't know how to create a different name for the instance using the number of the while cycle.