Experimenting with Play
play sound blocks and short script examples from the last page played in order—beginning with one block and then the next until there were no more blocks to play. However, we did see that what we actually heard depended on whether we waited until one sound was done playing before we began the next.
Navigate to the Events tab.
The first block (the
when green flag clicked block) is an event block. Event blocks are triggered by the corresponding described behavior. Scratch provides the green flag and red stop sign icons in the top right corner of the stage to begin and end the execution of programs. When the green flag is pressed, any (and all) sequences of blocks in your program beginning with a
when green flag clicked block begin executing.
Try it! Connect the
play sound blocks from the previous activity to a
when green flag clicked block, then execute your program by clicking the green flag.
Another type of event block is tied to the
broadcast block. This block allows us to have some control over which blocks are executed at a given time by communicating a message. When a message is
broadcast[...], the corresponding
when I receive [...] blocks are executed.
Create the following scripts in Scratch. Note that the Cat and the Duck sprites have completely separate script panes. Click on each character to see its script pane. This allows each sprite to have its own unique behaviors defined.
Note that the blocks are color-coded according to their function:
- The purple Looks tab contains the
sayblocks used in the example.
- Similarly, the brown Events tab contains the broadcast and when blocks.
When you are done, press the green flag to start the short play.
|For the cat:||For the duck:|
A note about style: You will notice that we chose to give meaningful names to the messages that were broadcast so that it would help us keep track of what we were doing and what messages we were sending. We recommend that you do this in your projects. As your projects grow in size, the number of unique names will grow accordingly. Choosing meaningful names will help you find errors more quickly.
To choose a new sprite from a library of existing sprites, click on the icon below the stage that looks like a head.