Deep Sea Sushi

Keeping Score

To keep score of how many fish the player catches, you’ll need somewhere to store the score, a way of adding to it, and a way of resetting it when the game is restarted.

First: storing the score!

Go to the Variables blocks category and click on Make a Variable.

Enter score as the name.

Check out your new variable!

The Score variable is displayed on the stage

What are variables?

When you want to store information in a program, you use something called a variable. Think of it like a box with a label on it: you can put something in it, check what’s in it, and change what’s in it. You’ll find variables in the Variables section, but you need to create them first for them to show up there!

Now you need to update the variable whenever the shark eats a fish, and to reset it when the game is restarted. Doing both is pretty easy:

From the Variables section, take the set [my variable v] to [0] and change [my variable v] by [1] blocks. Click on the little arrows in the blocks, choose score from the list, and then put the blocks into your program:

Code for the shark

whenclickedsetscoreto0setrotationstyleleft-rightgotox:0y:0

Code for the fish

iftouchingSprite1?thenchangescoreby1hidewait1secondsgotox:pickrandom-240to240y:pickrandom-180to180show

Cool! Now you’ve got a score and everything.