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

2015/10/14

Make Boolean Variable for Classes Eaten by Actor

baffled baffled

2015/10/14

#
I would like to stop the scenario once my Actor eats a specific number of other classes. I've been looking through documentation and I cannot figure this out. Please help.
danpost danpost

2015/10/14

#
A boolean value, not necessarily a 'variable', would be needed. This value would be used as a condition within an 'if' statement. If you had int field(s) to track how many of each type actor were eaten (generically called 'actorsEaten' in the following):
if (actorsEaten >= 10) Greenfoot.stop();
I guess you could make a variable out of it by something like the following, however:
boolean limitReached = actorsEaten >= 10;
if (limitReached) Greenfoot.stop();
For multiple actors:
boolean limitOneReached = typeOneEaten >= 10;
boolean limitTwoReached = typeTwoEaten >= 8;
if (limitOneReached && limitTwoReached) Greenfoot.stop();
It either limit alone could stop the game change '&&' to '||' ('AND' to 'OR').
You need to login to post a reply.