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

2016/2/13

3 kills = 1 point not working.

RussellBlo RussellBlo

2016/2/13

#
        Actor eatBread;
        eatBread = getOneObjectAtOffset(0,0, Strawberry.class);
        int bomb = 0;
    if (eatBread != null) {
        getWorld().removeObject(eatBread);
        bomb++;
        getWorld().addObject(new Strawberry(), (Greenfoot.getRandomNumber(1270)),(Greenfoot.getRandomNumber(710)));
    }
    if (bomb > 2) {
        Counter.target++;
        bomb = 0;
    }
I'm trying to make it so that when I kill 3 Frog.class's it will add 1 point to Counter.target,. Why does this code not work?
davmac davmac

2016/2/13

#
Because line 3 is resetting 'bomb' to 0 each time. If you want to keep a count that persists between calls to 'act', you need to use an instance variable.
You need to login to post a reply.