Variables can be thought of as containers for storing information.  When you create a new variable in Scratch, 3 new blocks are created. 

You can have two different sorts of variables: Local and Global.  Use global for a variable that can be used by all sprites.  Use local for a variable that just relates to a particular sprite. 

In this example we will start with the Fish Chomp game that comes with Scratch. 
Choose Open, go to Games, and choose FishChompWe will keep score of how many fish have been chomped.

Go to the Variables tab, and click Make a Variable.  Choose a global variable and name your variable FishEaten.  It is always a good idea to give your variables meaningful names.
If you want to see your FishEaten score as you play, tick the box to the left of the variable name.

script Now for each of the 3 gold fish, in their scripts add in a block 'Change FishEaten by 1' straight after the Broadcast got-me block.  Now as you play the game and chomp fish, you should be able to see how many you have eaten.


 
 If you stop and then restart the game, you will see we have a problem.  FishEaten has remembered how many fish were eaten from the last game.  You can fix this by initialising your variable at the start of the game.  (That means setting FishEaten to 0 at the beginning of the game) 
Do this in the script for the Stage.  Add in the following script for the Stage:

script

Let's further improve the Fish Chomp game by stopping it whenever the player has chomped 10 fish.  Add in the following to the stage script:

script


Finishing Off the Game

We can further improve the game by adding in another background for the Stage that says 'Game Over'.  Just copy the existing background and add in the writing.

background

Change your stage script to look like this:

script

Add the following into each of the 3 goldfish and the big fish

script

 

The only thing left to do is to initialise the background for the Stage, so that the game starts with the correct background.
Add in the following to the Stage script:

script

 

Work out a way to show the amount of time it takes the player to catch 10 fish.

Hint
: You could use a new variable called Time and give it the value of the timer when the game stops.