If you are not in the class that has the 'credits' field, then you need to access the value the same way as the other classes that do not have the field. Also, line 6 is incomplete -- no assignment is being made.
if (Credits > 0)
{
print (0);
} public Return()
{
GreenfootImage textImage = new GreenfootImage ( "Return Ticket" ,40, Color.WHITE, Color.BLUE);
setImage(textImage);
}
/**
* Act - do whatever the Return wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
GreenfootImage textImage = new GreenfootImage ( "Return Ticket" ,40, Color.WHITE, Color.BLUE);
setImage(textImage);
if (Greenfoot.mouseClicked(this))
{
if (getWorld().getObjects(Ticket.class).isEmpty()) return;
Ticket ticket = (Ticket)getWorld().getObjects(Ticket.class).get(0);
ticket.addCredits(-5);
System.out.println(""+ticket.getCredits());
}
}