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

2016/11/17

NEED HELP

ivo295 ivo295

2016/11/17

#
So in the code below I am spawning random monkeys called harambe. This code is in the act method in the world class. So the problem I am having is I want to spawn a DK monkey after a certain amount of harambes have been spawned. I tried with the count, as seen in the code but it didn't work. Also how can I stop harambes from spawning so i can spawn one big DK? public void act() { int x = Greenfoot.getRandomNumber(1000); int count = 0; if (x >=960) { count++; addObject(new Harambe(), -10,429); } if( count == 2) { addObject(new DK(), -10,390); } }
Super_Hippo Super_Hippo

2016/11/17

#
You create a new 'count' variable each time the act method is executed. You might want to create 'count' (or maybe with a more obvious name) like this instead: (outside methods)
private int count = 0;
You need to login to post a reply.