Page 98 - Learn To Program With Scratch
P. 98

3.  Detach the script connected to the when I receive DrawFlower
                             block and connect it to the define DrawFlower block, as shown in
                             Figure 4-12. This results in a new procedure, called DrawFlower,
                             that is implemented as a custom block. Delete the when I receive
                             DrawFlower block because it is no longer needed.







                                                                      This script was originally connected
                                                                      to the


                                                                      block. Detach it and connect it to
                                                                      the define DrawFlower block as
                                                                      shown here.


                             Figure 4-12: The DrawFlower procedure implemented as a custom block

                         4.  Now that we’ve created a DrawFlower procedure, we just need to call
                             it from the Draw message handler. Modify the Draw message handler
                             as shown in Figure 4-13. Note that we only replaced the broadcast
                             DrawFlower and wait block with our new DrawFlower custom block.










                                                           Replace the

                                                           block in the original script with the new
                                                           custom block.

                             Figure 4-13: Calling DrawFlower from the Draw message handler

                             The program is now complete, and you can test it. Click the mouse on
                         the Stage to verify that the program still works as before. See “Running
                         Without Screen Refresh” on page 77 to learn how you can speed up the
                         execution of this program.
                             Now that you know the basics behind custom blocks, you can take them
                         a step further by making blocks that can accept inputs.










           76   Chapter 4
                                           www.it-ebooks.info
   93   94   95   96   97   98   99   100   101   102   103