Notes:
Tip...
Give each variable a name that reminds you what is stored in it. For example, if you are creating a game and you use a variable to store the score, then a good name for the variable would be “game_score”.
If you wanted to use a two-word name for your variable, you would separate the words with an underscore (the “_” character), not a blank space.
Using variables in Scratch
Ok, now we’re going to create and use variables. Click on Variables in the Blocks Palette and create a variable called “game_score”.
1 Click on the Variables button, then on the button labelled “Make a variable”.
2 Drag “Set [game_score] to [0]” to the Scripts tab. Then, from Control,
This opens the “Variable name?” dialogue window. Enter the name “game_score” for your variable and click OK.
drag the block “when Sprite1 clicked”. Join the two together to make a script.
3 The default value for new
4 Finally, from Looks, I have used a “say [Hello] for [2] secs” block but changed it to “say [Great, I’ve got 100 points] for [2] secs”.
variables is “0”. Select the block “set [game_score] to [0]” and change the value to “100”.
A beginner’s guide to Scratch
24
Made with FlippingBook flipbook maker