Page 103 - Learn To Program With Scratch
P. 103

Figure 4-18: This version of Square takes the desired color as a second parameter .




                                                    try it out 4-1
                            What about the thickness of the square’s border? Modify the Square procedure
                            to take a third parameter, called penSize, that specifies the size of the pen to be
                            used in drawing the square .




                             Let’s conclude this section with some useful tips for dealing with cus-
                          tom blocks:

                          •   Custom blocks can’t be shared among sprites. If you create a cus-
                             tom block for, let’s say, Sprite1, then only Sprite1 can use that block.
                             Similarly, a custom block defined for the Stage can only be called by
                             scripts that belong to the Stage.
                          •   Give your parameters meaningful names that indicate what they’re
                             used for.
                          •   To delete a custom block, just drag its define block (that is, the hat
                             block) from the Scripts Area and drop it over the Palettes area. You
                             can only delete a define block if your project doesn’t contain any stack
                             blocks associated with it, so remove all uses of a custom block from your
                             scripts before trying to delete it.
                          •   To delete a parameter of a custom block, click the parameter’s name
                             in the Edit Block dialog and then click the small X icon that appears
                             above the parameter’s slot.
                          •   In addition to number inputs, you can also add string and Boolean
                             parameters. We’ll talk more about data types when we discuss variables
                             in the next chapter.

                             Now, you might wonder: Can a procedure call another procedure?
                          In the next section, you’ll learn about how to use nested procedure calls
                          to extend the power and usefulness of existing procedures.






                                                                                   Procedures   81

                                           www.it-ebooks.info
   98   99   100   101   102   103   104   105   106   107   108