title: Printing a score counter in greenfoot. Outputting zero
body: <p>I am trying to output a score in the greenfoot IDE and all is working fine (the score is increasing) until I try to print it. When I try to print it it changes to zero for some reason.</p>
  
  <p><strong>Crab Class:</strong></p>
  
  <pre><code>public class Crab extends Animal
  {
      int health = 10;
      int score = 0;
      public void act()
      {
          score = score + 1;
          System.out.println(score);
          //JOptionPane.showMessageDialog(null, newscore, "You lose!", JOptionPane.WARNING_MESSAGE);
          if (Greenfoot.isKeyDown("Left"))
          {
              turn(-3);
          }
          if (Greenfoot.isKeyDown("Right"))
          {
              turn(3);
          }
          if (canSee(Worm.class))
          {
              eat(Worm.class);
          }
          move();
          healthBar();
      }
      public void healthBar()
      {
          if (atWorldEdge())
          {
              Greenfoot.playSound("pew.wav");
              move(-20);
              turn(180);
              health = health - 1;
          }
          if (health &lt;= 0)
          {
              Message msgObject = new Message();
              msgObject.youLose();
              Greenfoot.stop();
          }
      }
  }
  </code></pre>
  
  <p><strong>Message Class:</strong></p>
  
  <pre><code>public class Message extends Crab
  {
      /**
       * Act - do whatever the Message wants to do. This method is called whenever
       * the 'Act' or 'Run' button gets pressed in the environment.
       */
      public void youLose() 
      {
          JOptionPane.showMessageDialog(null, "Try again next time. Your score was  " + score, "You lose!", JOptionPane.WARNING_MESSAGE);
      }    
  }
  </code></pre>
  
  <p>In the act method when I try to print out the score it shows it is increasing but when I print it out with <code>JOptionPane</code> or as normal at the end of the program it gives me 0.</p>
  
  <p>Example:</p>
  
  <p><a href="http://i.imgur.com/St0HARX.png" rel="nofollow">http://i.imgur.com/St0HARX.png</a></p>