I'm making a small game in Greenfoot to see what I can do again as I haven't done coding in a while due to isolation, I got a system which lets me travel from one world to another (thank you danpost) and I implemented it into my code, whenever you pick up an apple, a counter in the corner is increased by 1, but when the counter went up it fails because it tries to send it to both worlds. Is there any way of fixing this?
Code for Apple:
Actor Apple;
Apple = getOneObjectAtOffset(0,0,Apple.class);
if (Apple!=null)
{
Indoors indoors = (Indoors)getWorld();
indoors.removeObject(Apple);
Counter1 counter = indoors.getCounter1();
counter.bumpCount(1);
}
if (Apple!=null)
{
Outside outside = (Outside)getWorld();
outside.removeObject(Apple);
Counter2 counter = outside.getCounter2();
counter.bumpCount(1);
}
Code for Counter 1 and 2 is the same just 1 and 2 is swapped:]
public class Counter1 extends Actor
{
private int totalCount = 0;
public Counter1()
{
setImage(new GreenfootImage("0",20,Color.WHITE,Color.BLACK));
}
public void bumpCount(int amount)
{
totalCount += amount;
setImage(new GreenfootImage(""+ totalCount,20,Color.WHITE,Color.BLACK));
}
}
