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

2014/11/6

Counter

lozzi96 lozzi96

2014/11/6

#
so i have created a game like scenario where a ball moves around the world, i currently have that when the ball rolls over an actor 'point' the point disappears and i now want to create a system that counts how many 'point's youve collected but am unsure how... can anyone help? thanks
danpost danpost

2014/11/6

#
Just add an instance int field to the class of the ball and add one to it when it 'eats' a point.
Alwin_Gerrits Alwin_Gerrits

2014/11/6

#
So prety much just add a counter and up it in your method that makes the point disappear. Then call that counter if you want to know how many points have been collected. If you want to ask how much the counters value is from another class just declare it as a public (so 'int counter' outside of any method but inside your class)(not really called public, but works the same) and use newVariable = point.countername. Then just print newVariable or whatever name you gave the variable you want to hold the score. You could allso just print point.countername (by the way, point is your classname for the actor point).
You need to login to post a reply.