Mosquito Patrol

Keeping Score

To keep score, 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 it! Go to the Variables blocks category and click Make a Variable.

Enter score as the name.

Check out your new variable and the blocks for it!

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 under Variables, but you need to create them first!

Now you need to update the variable whenever a mosquito is eaten, and to reset it when the game is restarted:

From the Variables section, take the set [my variable v] to [0] and change [my variable v] by [1] blocks. In each of the blocks, click on the little arrow and then choose score from the list. Then put the blocks into your program:

Code for the parrot

whenclickedsetscoreto0setrotationstyleleft-rightgotox:0y:0

Code for the mosquito

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

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

Finally, add this code to make the parrot introduce the game:

whenclickedsetscoreto0setrotationstyleleft-rightgotox:0y:0sayHello! I need your help.for3secondssayCan you help me catch of all the mosquitos? Use the arrow keys.for4secondssayMosquitos are small flies that spread dangerous diseases like malaria.for5secondssayPlease help me catch them and protect my friends!for3seconds