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

2014/1/12

Counter Not Working

Lethal_Vitamin Lethal_Vitamin

2014/1/12

#
My Scenario The score should increment upon a circle being removed from the world, but it doesn't. Help!
danpost danpost

2014/1/12

#
First, the code to increase the score should be with the code that changes the value of 'clicked' to 'true'. Otherwise, you will increase the score multiple times while the fading occurs (once for each fade cycle). Your main problem is in accessing your MyWorld world where the 'getCounter' method resides: 'getWorld' return a World object (not classed as a 'MyWorld' object). You need to 'typecast' (cast the world object as of a 'MyWorld' type). In general:
MyWorld mw = (MyWorld)getWorld();
creates a field called 'mw' and tells the compiler that it is to hold a MyWorld object; then sets the world the actor is in to the value of that field (the world the field will now refer to). You can avoid the declaring of the Myworld field and directly deal with the counter in this way:
((MyWorld)getWorld()).getCounter().addScore();
The first part get the MyWorld object; the second gets the Counter object from that world; and the third increments the score of that counter.
Lethal_Vitamin Lethal_Vitamin

2014/1/12

#
Oh... Thank you, danpost.
You need to login to post a reply.