Step 7 – Keeping score
We'll need a way to keep score - don't worry, we'll give the Shark more Fish to catch in a bit!
- Set up a Variable called score – click Make a variable in the dark orange Variables section
Make sure that you call your variable something obvious like score
Variables are simply named areas of computer memory where we can store a value.
In this case, we want to store the score – how many fish our shark has caught.
We need to add some blocks in to deal with the score as the shark catches the fish.
- Add code to change the score variable by 1 when the fish is eaten – this goes below the Hide block inside the IF – THEN
Make sure you change to your score variable using the drop down
- You’ll also need to set the score variable to 0 at the start of the game – so add an orange set variable to 0 block right at the top of the Fish code.
Change myvariable to score again
- IMPORTANT: add an orange Wait 1 second block underneath the Set score to 0 block.
Sometimes the Fish will appear under the Shark which will catch them straight away – which means the score will never get as high as it should do...
This is all quite tricky. Just make sure you use the score variable each time, not the myvariable one that already exists.
Check that the game works. Makes sure that the score goes back to 0 when you start the game again.