KIDS
Visual programming environment means that
blocks on the screen represent basic programming
elements, and you assemble a series of instructions
by dragging-and-dropping the blocks together into
stacks. The blocks are color-coded and shaped
so they only fit together in ways that make sense
programmatically: the triggering events look like
folder tabs, and the subsequent steps fit together
like jigsaw puzzle pieces. Numbers fit into round
holes, text strings fit into rectangular text boxes,
and conditionals fit into diamond-sided holes that
look like decision points in a flowchart.
Familiarizing the Screen
Scratch’s main screen (Figure A) has 3 columns:
1. The program blocks are on the left, organized into
menus by type.
2. The middle column is where you stack the blocks
into a sprite’s scripts. Tabs at the top also let you
customize the sprite’s costumes (the different ways
it can appear) and the sounds it can make. You can
select costumes (Figure B) from a native library of
animals, things, and people, or else design your own
using the Paint Editor pane (Figure C). Similarly,
you can select sounds from a library of effects, or
record your own by clicking the Record button.
3. The right column contains the stage, where the
game’s action takes place. When you first open the
program, the stage is a white rectangle containing
one sprite, the orange cat that’s Scratch’s icon. To
run and stop your game, you click the green flag or
the stop-sign button above the stage.
Below the stage, you see thumbnails of all the
sprites in your game. This is where you manage
your cast of characters, creating new sprites and
selecting the one you’re working on. There’s also
a thumbnail for the stage itself, because it works as
a special sprite; you can control its appearance, to
paint backdrops, for example, but you can’t make
it move around.
and blocks that determine their flow, such as loops
and if statements. Add a forever block under the green
flag block; this sets up an endless listen-respond
loop. Next, drag 4 if blocks into the forever loop. We’ll
use these to check for the 4 different arrow keys.
Look under the Sensing tab and drag a key
[space] pressed? block into one of the if block slots.
In this game, we want to know if the arrow keys are
pressed, not the space bar, so click the box in the
block and change space to one of the arrow keys. Fill
the other 3 if blocks to sense the other 3 arrows.
Under the Motion category, move a change x by 10
block into the if blocks for the right and left arrows,
and a change y by 10 into the up/down blocks. To
correct the directions for left and down, put a minus
sign (–) in front of the 10.
Your program should look like Figure D. Click the
green flag, and you should be able to maneuver the
cat around the screen. You can see that the if statements inside the forever loop evaluate as true if the
key is pressed and false if not. The movement blocks
then adjust the position of the cat accordingly.
Walking the Cat
To illustrate Scratch programming technique, here’s
how you can make the cat move with the arrow keys.
To start a program, open the Control program blocks
on the left and drag the first block, when (green flag)
clicked, into the center of the Scripts pane. This block
instructs the program to start this script as soon as
the program is started.
The Control tab contains blocks that trigger scripts
Adding Complexity
This program is very simple, but complex programs
can be difficult to follow. To help with this, Scratch
has a Single Stepping mode that lights up each
block as it evaluates during runtime. To turn it on, go
to the Edit menu and select Start Single Stepping.
To expand your program, you can add blocks to
your current scripts or start new scripts. To create
a new script, go to the Control category and drag
over a new when block. This technique of creating
different scripts that run in parallel allows you to
separate the movement functionality, for example,
from that of any weapons or jumping.
There are other types of code blocks besides
Control, Sensing, and Motion: Variables blocks let
you use global variables to store things like speeds
or the number of lives or bullets left; Operators
blocks perform simple arithmetical, logical, and text
string functions; Pen blocks let sprites draw lines;
and Looks blocks control a sprite’s costumes, speech
balloons, and other aspects of its appearance.
You can use costumes to create the illusion that
a sprite is moving. Click the Costumes tab, and you
see that the orange cat has 2 different costumes.
Use Looks blocks in a script to alternate between
these, and the cat will appear to walk. Timing is
important here; to avoid a too-fast blur, put a wait
134 Make: Volume 21