The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

(^72) THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE
then add a when clicked block from the Events category to the scripts area. Next, add a
say Hello! for 2 secs block from the Looks category, then click on it to change it to say ‘Hello!
British ESA Astronaut Tim Peake here. Are you ready?’
when clicked
say Hello! British ESA Astronaut Tim Peake here. Are you ready? for 2 secs
Add a wait 1 secs block from the Control category, then a say Hello! block. Change
this block to say ‘Hit Space!’, then add a reset timer block from the Sensing category. This
controls a special variable built into Scratch for timing things, and will be used to time how
quickly you can react in the game.
when clicked
say Hello! British ESA Astronaut Tim Peake here. Are you ready? for^2 secs
wait^1 secs
say Hit Space!
reset timer
Add a wait until Control block, then drag a key space pressed? Sensing block into its
white space. This will pause the program until you press the SPACE key on the keyboard, but
the timer will continue to run – counting exactly how long between the message telling you to
‘Hit Space!’ and you actually hitting the SPACE key.
when clicked
say Hello! British ESA Astronaut Tim Peake here. Are you ready? for^2 secs
wait^1 secs
say Hit Space!
reset timer
wait until key space pressed?
You now need Tim to tell you how long you took to press the SPACE key, but in a way that’s
easy to read. To do this, you’ll need a join Operators block. This takes two values, including
variables, and joins them together one after the other – known as concatenation.

Free download pdf