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

2019/2/6

Counter for lives not incrementing or decrementing.

1
2
danpost danpost

2019/2/8

#
Notted wrote...
Do you want me to remove the return type and call for the playerLives method?
I find it difficult to say what you should do. I am still a bit confused over the different variables. Maybe if you specify exactly what each is tracking --. I mean, it seems to me like numOfBuckets would be equivalent to playerLives.
Notted Notted

2019/2/8

#
playerLives (now called numOfBucketsRefA to avoid confusion), tracks and is a reference to numOfBuckets. As of now, I removed the return type and call for the playerLives method. If you want to know what is doing the decrementing of the numOfBucketsRefA, check here:
if (bombBoom())
       {
           numOfBucketsRefA--;
           //losingSound.play();
       }
danpost danpost

2019/2/8

#
Notted wrote...
playerLives (now called numOfBucketsRefA to avoid confusion), tracks and is a reference to numOfBuckets. As of now, I removed the return type and call for the playerLives method.
Alright. Assignment statements, as such:
int numOfBucketsRefA = ((MyWorld)getWorld()).getABucket().getNumOfBuckets();
does not link the two. It only copies the value of the one to the other. So, any change to numOfBucketsRefA will not be reflected in numOfBuckets. Could that fit your issue?
Notted Notted

2019/2/8

#
Likely yes. numOfBuckets is in the bucket class. But the bucket class has no say whether or not a bomb hits the boomArea. The boomArea itself determines that. I want to decrement the lives (numOfBuckets from the bucket class) every time bombs hit the boomArea (bombBoom checks for this). If referencing the numOfBuckets as numOfBucketsRefA won't work, what will? I, sadly, don't have any real idea.
danpost danpost

2019/2/8

#
Instead of getting the value from the bucket object, you should probably just call a method on the bucket object that deals with it right there in the bucket class.
Notted Notted

2019/2/8

#
Still not working:
rivate void playerLives()
    {
      MyWorld kaboomWorld = (MyWorld) getWorld();
      boolean bombBoomRefA = ((MyWorld)getWorld()).getBoomArea().bombBoom();
      GreenfootSound losingSound = new GreenfootSound("lose.wav");
       if (bombBoomRefA)
       {
           numOfBuckets = numOfBuckets - 1;
           //losingSound.play();
       }
    }
    private void checkGameEnd() 
    {
        if (numOfBuckets == 0)
        {
            Greenfoot.stop();
        }
    }
Maybe this is causing the problem?
boolean bombBoomRefA = ((MyWorld)getWorld()).getBoomArea().bombBoom();
I want an area to be casuing the bombs to blow up, but I want it to decrease the number of lives I have everytime the bomb hits that area.
danpost danpost

2019/2/8

#
I think you misunderstood. The playerLives method in the BoomArea class needs to call a method in the bucket class named something like bombed or loseABucket. This method in the bucket class can then proceed to decrease numOfBuckets and check for game over. Never ask (using conditions) when you can just say "do it". Once you determine the bomb area has been bombed (in the BoomArea class), there should be no more checking on anything -- just straight processing. Well, not anything. But, as far as the bombing itself is concerned, yes anything. The game over state is something that needs checked anytime a life is lost.
Notted Notted

2019/2/14

#
Strange. After doing a bit of debugging, I found that bombBoom never returns true; it's always false, even when the bomb hits it. Is it supposed to do that? I would like to use this for my lives system, whenever the bombs hit the boomArea (bombBoom is now true. False is when the bomb is in the air falling down.)
Notted Notted

2019/2/14

#
Notted wrote...
Strange. After doing a bit of debugging, I found that bombBoom never returns true; it's always false, even when the bomb hits it. Is it supposed to do that? I would like to use this for my lives system, whenever the bombs hit the boomArea (bombBoom is now true. False is when the bomb is in the air falling down.)
Just fixed it as of now. The problem was that boomBoom was being called in the act method of boomArea.
You need to login to post a reply.
1
2