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

2015/9/1

Trying To make ScoreBoard on my Game!!!!(Not Working)

1
2
3
4
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Cool! Thats working now! The counter increases everytime I click a bubble, now the terminal is pointing out this:
if (getY() > getWorld().getHeight()+10)
        {
            getWorld().removeObject(this);
        }
The terminals error line says: java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:681) at greenfoot.Actor.getY(Actor.java:170) at Bubble.act(Bubble.java:19) at greenfoot.core.Simulation.actActor(Simulation.java:594) at greenfoot.core.Simulation.runOneLoop(Simulation.java:552) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
That's in the Bubble class.
Super_Hippo Super_Hippo

2015/9/2

#
Ah right, sorry for that... Remove it and put this at the beginning of the act method:
        if (getY() > getWorld().getHeight()+10)
        {
            getWorld().removeObject(this);
            return;
        }
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Cool Thanks so much Hippo(I read your wall ;))! I've learnt alot from your help and hope to repay you some day! :)
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Oh and it is talking about line 1 in the error. That didn't work...
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
I think it has something to do with the call of "getHeight()" outside of a world object.
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
I followed you on your wall. :)
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Bye, I have to go now, Thanks for the help! I will read the rest of your help tomorrow! Btw, I live in Australia so time will be different for you. :) Bye then! See you tomorrow maybe :)
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
I will read all of your messages tomorrow.
Super_Hippo Super_Hippo

2015/9/2

#
Did you change it? The error occurred because the object was removed (you clicked it) and then afterwards, it tried to get its y-coordinate. This isn't possible because it was removed from the world. If you put it at the beginning of the act-method and add this 'return' there as suggested, it will leave the act-method if the bubble reaches the bottom and got removed. So it looks like this:
public void act()
{
    if (getY() > getWorld().getHeight()+10)
    {
        getWorld().removeObject(this);
        return;
    }
    
    if (Greenfoot.mouseClicked(this))
    {
        ((Background) getWorld()).getCounter().addScore(1);
        getWorld().removeObject(this);
    }
}
As an alternative, you can also just add the 'return' statement after removing the object with clicking it, but I changed the order of actions because I think that it is "easier for the computer to compare two values than checking for a click".
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Just woke up, will test it now. :)
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
It worked! :D
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Now all I need to do is when the bubbles touch the bottom of the world a game over screen appears and tells the user their score. Thanks so much Supper_Hippo! Your awesome!!!
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Because when the bubbles touch the bottom of the world thats game over! Because the point of the game is to not let any bubbles touch the floor!
danpost danpost

2015/9/2

#
I just put up a new scenario. It is tutorial on displaying values,Value Display Tutorial. It does not specifically discuss a game over screen, but does touch on drawing text images onto larger images and that is basically what you would do for a game over screen. Using a simple actor for your counter and timer as discussed in the tutorial would make things a whole lot easier for you.
There are more replies on the next page.
1
2
3
4