Operation Manual
Drag another if block from the Control palette along with another touching ? sensing block, and this time, change the Sensing
block so both blocks together read if touching Sprite2?. Into this block, insert a wait 1 secs Control block with the
value changed to 2 and a say Hello! for 2 secs Looks block with the message changed to read Yum-yum-yum!. Finally,
drag the whole stacked block up so it connects to the bottom of the existing when right arrow key pressed block,
beneath the move 10 steps block. The final code for the cat sprite should look like the blocks in Figure 10-10.
Figure 10-10: The completed code for the simple Scratch game’s cat sprite
If you move the cat towards the Cheesy-Puffs with the right-arrow key on the keyboard, the game starts. When the cat reaches
the Cheesy-Puffs, the dialogue exchange takes place and the bowl should disappear.
Although this example is effective for introducing some important programming concepts, it’s hardly the best way the game could
be coded. Scratch includes a message broadcast system that allows code attached to one object to communicate with code
attached to another, which enables you to create much neater collision results that don’t rely on carefully-timed pauses in order
to make sense.
To experiment with broadcasting, try using the broadcast and when I receive blocks from the Control palette. A message
created for a broadcast block in any object can trigger code in any other object using the when I receive flag, meaning you
can use it to link multiple objects and their code together.
Robotics and Sensors
In addition to purely software-based inputs and outputs, it’s also possible to tie Scratch into external hardware using sensor
boards and robotics systems. Thanks to its multithreaded nature and powerful inter-process messaging system, Scratch can be
used to create a surprisingly advanced robotics engine and is by far the easiest way to place a Raspberry Pi at the heart of a
simple robot.
Unlike Python, which is a more powerful but significantly more complex programming language, Scratch can’t make use of the
Raspberry Pi’s GPIO port to communicate with external hardware. As a result, it needs some additional equipment before it can
interact with the physical world.
Sensing with the PicoBoard
Designed by the SparkFun electronics company, the PicoBoard is an add-on module that connects to a computer running
Scratch and provides a variable slider input, a light sensor, a button, a sound sensor and four pairs of alligator clips that can be
used to monitor external electrical devices.
There are currently two types of PicoBoard: the original model, which uses a serial connection, and its replacement, which uses a