Events and listeners are another extremely important part of computer science, and will be especially useful in creating your animated stories.
Events are anything that can happen during our animation.
Listeners are pieces of code that wait for those events and then run when they happen.
Let’s try think of some real-life events and listeners. Some events could be:
And the listeners might look like this:
In these examples, we are waiting (or listening) for some event to happen, like a door opening, then responding with some action.
In Scratch, there are lots of built-in events in the yellow Events section. Let’s take a look at a few of them:
Here’s a quick example using the Loudness event listener.
When your microphone is enabled, the sprites will listen for loudness, or volume before doing or saying the next action. The code for the above animation looks something like this:
A video example of how to use this code can be found in the Final Presentations section.