The purpose of this code is to count up how many WaterDrops have been collected by the Umbrella.
A variable is a space in memory (of the computer), which is used to store useful information. Variables contain data, which may be numbers, text or a combination of both.
In this example, a variable called waterdropsCollected is used. A value of 1 is added to it, each time a WaterDrop is collected.
Click on the video tutorial below and this will show you the code to count
There are several ways to count in Greenfoot. We have just looked at the use of a variable to count, but to get top end marks in the GCSE exam, you need to use a Counter class, which is simply another Actor, with counting code (a method) inside it.
Sometimes, in our exam, the scenario given to us will include a Counter class, which will contain pre-written code to help us count. If we can read and understand the code in the Counter class (actor), we can use it to add 1 onto our Counter.
However it is simpler to delete the Counter class already in the scenario. We can then import a Counter class from Greenfoot and can be sure the code we write will ALWAYS work for this class.
Click on the video tutorial below and this will show you how to import and use the Greenfoot Counter class.