Page 101 - Learn To Program With Scratch
P. 101
Technically, that’s all what we need to do to add a number slot to our
procedure. If we click OK, we’ll have a Square block that takes a number
as input. We could drag this block into our scripts and specify the desired
length in the parameter slot, as in Square 50. But how would a user know
what the number passed to Square means? Does it mean an area of 50, a
diagonal of 50, a side length is 50, or something else?
Imagine if Scratch’s glide block were designed like this:
How would you know that the first slot represents time (in seconds) and
the second and third slots represent the x- and y-coordinates of the target
glide point? The Scratch designers made the glide block easier to under-
stand and use by adding labels to these slots as follows:
Let’s do the same thing for our Square block by adding text that
describes the meaning (or usage) of the parameter slot. Click Add label
text x, as shown in Figure 4-15, to add a label after the side parameter.
Type steps for the label text and click OK.
Now, if you examine the definition of the Square procedure in the
Scripts Area, you’ll see a small block (named side) added to its header, as
illustrated in Figure 4-16 (left). The move block still has the fixed num-
ber 100 inside it, but all we need to do now is drag the side block from the
header of the Square method and drop it over the parameter slot of the
move block to replace the number 100, as shown in Figure 4-16 (right).
Drag the side label The complete
over the fixed number procedure
(100) to replace it.
Figure 4-16: Modifying the Square procedure to use the side parameter
The label, side, that appears in the header of the Square procedure is
called a parameter. You can think of a parameter as a named placeholder.
We wanted our Square procedure to be able to draw squares of any size, so
instead of hard-coding a fixed number inside our procedure, we used a gen-
eral parameter named side. Users will specify the exact value of side when
they call the Square procedure. Let’s illustrate this point by modifying the
script in Figure 4-14 to use the new version of our Square procedure. The
required changes are illustrated in Figure 4-17.
Procedures 79
www.it-ebooks.info

