Lessons
|
Event-Driven Programming
Before you can fully appreciate the usefulness of the broadcast blocks you first need to understand the concept of event programing. Many programs are made using this model. In simple terms, event-driven programming means that your program, or parts of your program, won't execute until an event has happened. The event is used to trigger a part of the program that executes a set of commands. An event can be when a key is pressed on the keyboard or when a button is clicked with the mouse. For example, when you are surfing the web with internet explorer and you click on the back button. Clicking on this button causes the program to execute a set of commands for that button. The program won't do anything until you click on that button. Most actions in a program can be thought of in this way.
In relation to scratch, you can think of it this way. You have 20 sprites in your program but you don't want them all of them on the stage at the same time. You only want a few sprites on the stage at any one time. You can have some of the sprites appear and disappear using event-driven programing and the broadcast control blocks. When an event, say clicking on a sprite, happens you can have one sprite disappear and have another appear. The sprite wont disappear or appear until the event, clicking on a sprite, happens. Read below to learn how use the broadcast block. Broadcasting
The broadcast block is both a control block and a stack block. It's function is to send or broadcast a signal throughout the whole Scratch program. Any scripts that are hatted with the When I Receive block will execute their script when they receive the broadcast. The script won't execute until it receives the broadcast. This block can be used to have a sprite respond to the actions of another sprite or event.
Broadcast blocks are a good way to have sprites and scripts communicate. It gives sprites the ability to send and receive broadcast messages as a means of coordinating script execution. |