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

2013/4/2

How to do you declare variable?

gquach gquach

2013/4/2

#
I was doing green MyClara, and I wanted The ladybug to move and count leaves being stepped on top of. Once it's in front of a tree, it shows the total of leaves being stepped on. How do you do that?
Game/maniac Game/maniac

2013/4/2

#
Declare an integer in your World subclass and call it leavesEaten, then in the method for eating the leaf put:
/*World subclass name*/ world = (/*World subclass name*/)getWorld();
world.leavesEaten++;
JetLennit JetLennit

2013/4/2

#
what does the
 world.leavesEaten++;   
mean?
Joep Joep

2013/4/2

#
it means you add one to your variable leavesEaten. If your leaves eaten = 2, after calling this your leavesEaten = 3
JetLennit JetLennit

2013/4/2

#
so it adds 1?
danpost danpost

2013/4/2

#
Yes. The three statements below are equivalent:
leavesEaten = leavesEaten + 1;
leavesEaten += 1;
leavesEaten++;
JetLennit JetLennit

2013/4/2

#
okay... i was wondering... and is the a --?
danpost danpost

2013/4/2

#
Yes. Similarly, the same are
leavesEaten = leavesEaten - 1;
leavesEaten -= 1;
leavesEaten--;
But I guess this would mean you barfed it back up!
You need to login to post a reply.