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

#
What does not a statement mean?? Just for my learning :P
Super_Hippo Super_Hippo

2015/9/2

#
This line?
((Background) getWorld()).getCounter().addScore(1);
Well, to be honest, I don't know what is wrong. You could change it to one of the following and report back if anything changes:
(Background) getWorld().getCounter().addScore(1);
Background b = (Background) getWorld();
b.getCounter().addScore(1);
Background b = (Background) getWorld();
Counter c = b.getCounter();
c.addScore(1);
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Thank you. :) I will test them now.
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
It worked this time but know the console gave me an error talking about the (Background) b thing again when I clicked the bubble...
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Now the terminal window keeps giving me errors everytime I click a bubble...
Super_Hippo Super_Hippo

2015/9/2

#
What did the console print out?
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
So the code does compile and work but when I click a bubble the output terminal window pops up and tellls me about the attempt to use a method from another class...
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
This: java.lang.NullPointerException at Bubble.act(Bubble.java:16) 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

#
When you get time can you please explain what this error means, so I learn a bit more. :)
Super_Hippo Super_Hippo

2015/9/2

#
Which line is line 16 now? (So is b or c null?) And did you change anything in the world code? Nullpointer Exception means that you try to call a method on 'null' which doesn't work. b would be null if the object wouldn't be in the world (which doesn't really make sense because you clicked it). c would be null if 'theCounter' in the world would be null.
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Yes, I did change something in the world code, I changed the private Bubble Bubble to private Bubble bubble; and I deleted the two other objects(counter, bubble) that you said. Thats it. C is the null one... Well, that's what the console says anyway, the code looks right to me...
Super_Hippo Super_Hippo

2015/9/2

#
So you still have this in your world?
Counter counter = new Counter();
addObject(counter, 128, 56);
If yes, change it to the following:
theCounter = new Counter();
addObject(theCounter, 128, 56);
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
"theCounter" and the "bubble" are both returning null when I right click on the world and press "Counter getCounter()". They both are returning null? Do you know how to make them return true?
Super_Hippo Super_Hippo

2015/9/2

#
They shouldn't return 'true'. You can remove the 'private Bubble bubble' and the 'getBubble' completely, they aren't needed anymore. Try the last change I suggested. Then the 'getCounter' method should return the object.
Sceuby_Doo23 Sceuby_Doo23

2015/9/2

#
Okay, I will try it! :)
There are more replies on the next page.
1
2
3
4