Beginner Events
Contents
Introduction
When you press the power button on the TV remote what happens? The button is an “event” that gives a signal to the TV to turn on or off. Can you think of any other events that give signals? For example, what happens when an alarm clock goes off? What does that make happen?
As a coder, sometimes you want your program to be able to respond to the user when the user wants it to. That is what events are for. An event is an action that causes something to happen. In earlier activities, you created algorithms that allowed you to control a friend or Flurb for several steps at a time. It was fun and useful, but what happens when you don’t know everything that you want your friend to do in advance? This is where events come in. In these activities, you’re going to practice changing programs by introducing events.
What is it?
An event is an action that causes something to happen.
Activities
The Big Event
This is an Event Controller – a sound machine that is controlled by events with the push of a button. With your team, decide what each button does. For example, when the green button is pressed, we clap our hands. When the yellow button is pressed, we say “Boom!”
Take turns tapping the buttons, so that the rest of your team can see and react with your sounds. Add some button sequences into the mix and have your team try to keep up. Every time you push a button, it is an event that lets you know what they are expected to do next.
Race to the Finish.
Get ready for the 2016 Olympic Games in Brazil by making a game where two characters race each other. Work in pairs to follow the step-by-step instructions for the Race to the Finish project.
When you’re done, make a two-player game by adding another sprite and adding the same code blocks to control your new sprite.
Review
- What's the event that makes the player move forward?
- What event makes the sprite go back to the started point?
Optional Challenge
Use a “broadcast” event block so that when one player finishes the race, the other player says something like: “Boo hoo!” or “Nice run, want to try again?”
You can do this by adding a “broadcast” block for each sprite, just after they say “I made it!” Select the drop-down menu in the Events menu and then “New Message.” Call your message something simple, like “win.”
Then, drag out the “When I receive” block and select the broadcast name you created earlier. Within that block, you can add whatever you want the losing sprite to say: