The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

(^60) THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE
Click on the green flag above the stage to run the program. You’ll see the cat move to
the right, make a meow sound – make sure you’ve got speakers or headphones connected
to hear it – then move back to the start again. Click the flag again, and the cat will repeat
its actions.
Congratulations: you’ve created a sequence of instructions, which Scratch is running
through one at a time, top to bottom. While Scratch will only run one instruction at a time
from the sequence, it does so very quickly: try deleting the play sound meow until done
block by clicking and dragging the bottom move -10 steps block to detach it, dragging the
play sound meow until done block to the blocks palette, then replacing it with the simpler
play sound meow block before dragging your move -10 steps block back onto the bottom
of your program.
when clicked
move^10 steps
play sound meow
move -10 steps
Click the green flag to run your program again, and the cat sprite doesn’t seem to move. The
sprite is moving, in fact, but it moves back again so quickly that it appears to be standing still.
This is because using the play sound meow block doesn’t wait for the sound to finish playing
before the next step; because the Raspberry Pi ‘thinks’ so quickly, the next instruction runs
before you can ever see the cat sprite move. There’s another way to fix this, beyond using the
play sound meow until done block: click on the Control category of the blocks palette,
colour-coded gold, then click and drag a wait 1 secs block between the play sound meow
block and the bottom move -10 steps block.
when clicked
move^10 steps
play sound meow
wait^1 secs
move -10 steps

Free download pdf