The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

(^56) THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE
Your first Scratch program: Hello, World!
Scratch 2 loads like any other program on the Pi: click on the raspberry icon to load the
Raspbian menu, move the cursor to the Programming section, and click on Scratch 2. After a
few seconds, the Scratch 2 user interface will load.
Where most programming languages need you to tell the computer what to do through
written instructions, Scratch is different. Start by clicking on the Looks category in the
blocks palette, found in the centre of the Scratch window. This brings up the blocks under
that category, coloured purple. Find the say Hello! block, click and hold the left mouse
button on it, and drag it over to the scripts area at the right-hand side of the Scratch window
before letting go of the mouse button (Figure 4-1).
5 Figure 4-1: Drag and drop the block into the scripts area
Look at the shape of the block you’ve just dropped: it has a hole at the top, and a matching
part sticking out at the bottom. Like a jigsaw piece, this shows you that the block is expecting
to have something above it and something below it. For this program, that something above
is a trigger.
Click on the Events category of the blocks palette, coloured light brown, then click and drag
the when clicked block – known as a hat block – onto the scripts area. Position it so that

Free download pdf