This site requires JavaScript, please enable it in your browser!
Greenfoot back
chelle526
chelle526 wrote ...

2011/12/5

How to create an integer variable for numOfLeaves() eaten

chelle526 chelle526

2011/12/5

#
I'm new at this can anyone help?
Morran Morran

2011/12/5

#
Inside of the class that eats the leaves(I'm guessing that you are doing the Wombats tutorial), at the top of the class, add a variable and call it whatever you want, like this:
public class eaterOfLeaves extends Actor
{
    //you can put your variable to keep track of leaves eaten(it would be an instance variable) right below:
    private int numOfLeavesEaten
 
    //the rest of your class
}
Then, when you want to eat a leaf, also update the numOfLeavesEaten, by typing numOfLeavesEaten++. When you want to check how many have been eaten, just get the value of numOfLeavesEaten.
chelle526 chelle526

2011/12/6

#
thanks
You need to login to post a reply.