Operation Manual

A beginner’s guide to Scratch
36
Have a look at the screenshot above. We have used the “when [space] key
pressed” event from Control to run the program. The robot sprite is moved to the
centre of the screen using a “go to x: [0] y: [0]” block from Motion (see “Positioning
your sprite”, in Lesson 1.3).
The rest of the code is placed inside a “repeat until” loop (from Control). Inside the
repeat loop, we have an “if” (a conditional statement) that checks if the “up arrow”
key has been pressed. This has been set to a “key [up arrow] pressed” event
(from Sensing).
The “touching [ ]?” block from Sensing is set to “edge”. That means that if the
robot touches the edge of the Scratch screen, the event will stop the script.
An “event” is something that happens in a program.
In this script, there are two possible situations:
1. The “up arrow” key has been pressed – in which case, the robot will walk up the
screen for 20 steps, switching costumes as it does so.
2. The “up arrow” key has not been pressed – in which case, the robot will
do nothing.
That’s not going to be very useful. Let’s see if we can do better.
To see an example of this script, open RPiScratch/Projects/robot_v1.
This script will
make our robot
move on our
command, but
only in one
direction.
Notes: