Working with variables in Scratch to make a score

November 17th, 2010 by Brian Leave a reply »

My demo game for today in Scratch involves checking to see if a button is pressed, changing a variable and a costume if it’s pressed, and then checking if the required score has been met.

The variable is boot to the head. *

When the green flag is clicked to start the game, we reset boot to the head and the costume to give the player a fresh start.

Next, we check to see if the spacebar has been pressed. If it has, we change boot to the head by one and do a mini-animation of a cat with a boot to the head. I put a wait command in there so the user’s eye can actually see the costume change.

We use an “if…” statement (found in the Control section) and use an operator (the green section) to see if boot to the head equals 10, our designated end of the game. If the player has 10 boot to the heads (boots to the head?), we reward them with a positive message of encouragement and then cruelly reset the score.

This is my demo, but I know that you’ll need variables to keep track of info in your games for the competition. Use the same techniques for your own variables.

Notice the big red X. The “if…” statement won’t work if it’s not connected to the rounded top of “When space key pressed”.

Your code should look like this for the demo:

*In no way does Mr. Griggs endorse giving walking cats a boot to the head.


Leave a Reply