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

2013/3/23

Heath Bar

1
2
GrimCreeper312 GrimCreeper312

2013/3/24

#
i believe line 37 is the 56 line in the class
GrimCreeper312 GrimCreeper312

2013/3/24

#
sorry line 6 is the 56th line in the class
danpost danpost

2013/3/24

#
Then you must have set the minimum value equal to the maximum value, which produces a difference of zero, causing the error.
danpost danpost

2013/3/24

#
I did not think that was possible. You must be by-passing the methods supplied in the Bar class to set the values or you set the default minimum and maximum fields to the same value.
GrimCreeper312 GrimCreeper312

2013/3/24

#
here is a copy of my worlds instance field, constructor, and act method
public class Mw extends World
{
    public static int life;
    Bar bar = new Bar("", "Health", 20, 20);
    Bar scoreBar = new Bar("Score", "points", 0, roundScore);  
    public static int score;
    
    public Counter counter;
    
    public static boolean canMove;
    
    public static int money;
    
    public static int roundScore;
    public static int round;
    
    /**
     * Constructor for objects of class Mw.
     * 
     */
    public Mw()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1100, 550, 1); 
        life = 20;
        score = 0;
        prepare();
        money = 0;
        round = 1;
        canMove = true;
        roundScore = 500;
        upRound();
        counter = new Counter();
        addCounter();

 public void act()
    {
        randomAddAnts();
        endScreen();
        addRoundOver();
        bar.setValue(life);    
        scoreBar.setValue(score);
        
    }
    }
danpost danpost

2013/3/24

#
You are creating the scoreBar object before setting 'roundScore' to 500, meaning 'roundScore' is still zero. Remove line 31 and move line 14 to before line 5, changing it to
public static int roundScore = 500;
GrimCreeper312 GrimCreeper312

2013/3/24

#
thanks
You need to login to post a reply.
1
2