The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1
Chapter 4 Programming with Scratch^63

THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE


First, click the File menu and save your existing program by clicking on Save Project. Next,
click File and then New to start a new, blank project. Click on the Data category in the blocks
palette, then the ‘Make a Variable’ button. Type ‘loops’ as the variable name (Figure 4-5),
then click the OK button to make a series of blocks appear in the blocks palette.


5 Figure 4-5: Give your new variable a name


Click and drag the set loops to 0 block to the scripts area. This tells your program to
initialise the variable with a value of 0. Next, click on the Looks category of the blocks palette
and drag the say Hello! for 2 secs block under your set loops to 0 block.


set loops to^0


say Hello! for^2 secs


As you found earlier, the say Hello! blocks cause the cat sprite to say whatever is written
in them. Rather than writing the message in the block yourself, though, you can use a variable
instead. Click back onto the Data category in the blocks palette, then click and drag the
rounded loops block – known as a reporter block and found at the top of the list, with a

Free download pdf