by David J. Malan <malan@post.harvard.edu>
Printer-Friendly Version of Tutorial

« Previous | Table of Contents | Next »

Events

In programming, multiple threads can communicate with each other by signaling events and handling events. An event, then, is like a message from one thread to another. In Scratch, blocks whose labels begin with "broadcast" signal events whereas blocks whose labels begin with "when" handle events, the latter of which, recall, effectively represent threads themselves.

A block that signals an event is:



A block that handles an event is:



Not only can events be signaled by blocks, they can also be signaled by a user's actions. Clicking Scratch's green flag, for instance, effectively signals an event that is handled by:



In Scratch, not only do events enable threads to communicate, they also allow sprites to communicate with each other. For instance, two sprites might want to play Marco Polo with each other, with one sprite's behavior defined by the leftmost thread below and the other sprite's behavior defined by the rightmost thread below:



Out of statements, Boolean expressions, conditions, loops, variables, threads, and events can you construct interesting (and fun) programs. In fact, let's explore the inner workings of what, on first glance, appears to be a very complex program but, ultimately, is just an application of these building blocks.

Let's turn our attention to Oscartime!

« Previous | Table of Contents | Next »