i have a money counter which is in one of the actors, how can i get another actor also add to the same counter
// This is in ActorA static int money_counter;
ActorA.money_counter = 0;
ActorA.money_counter = ActorA.money_counter + 5;
import greenfoot.*;
import java.awt.Color;
public class Counter extends Actor
{
int value = 0;
public Counter()
{
updateImage();
}
public void add(int amount)
{
value += amount;
updateImage();
}
public int getValue()
{
return value;
}
private void updateImage()
{
setImage(new GreenfootImage("Score: " + value, 24, Color.black, new Color(0, 0, 0, 0)));
}
}// in the actor class act method (or method it calls)
if (whatever == true) addToCounter(10);
// and add the following method
private void addToCounter(int addAmount)
{
WorldName world = (WorldName) getWorld();
Counter counter = (Counter) world.getObjects(Counter.class).get(0);
counter.add(addAmount);
}