Computer Science Grade 5 20 min

Event-Driven Storytelling: Interactive Stories

Create an interactive story where events trigger different parts of the narrative.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define 'event' and 'event handler' in their own words. Identify at least three different types of user events in a program (e.g., mouse click, key press, sprite collision). Create a simple 'When [event] happens, do [action]' rule in a block-based coding environment. Connect a user event to a specific story action, like clicking a character to make it talk. Use a simple conditional (if/then) inside an event handler to create a choice. Explain how event-driven programming makes a story interactive and gives control to the player. Sequence two or more events to create a simple story path. Have you ever played a game where clicking a treasure chest makes it open? How does the computer know you clicked it and what to do next? 🤔...
2

Key Concepts & Vocabulary

TermDefinitionExample EventAn action that happens in a program, usually caused by the user. The program waits for these to happen.Clicking the mouse, pressing the 'A' key on the keyboard, or one character touching another. Event HandlerA special block of code that is always 'listening' for a specific event. When that event happens, the code inside the handler runs.A 'When this sprite clicked' block is an event handler. It waits for a click on that specific character. User InputAny action the user takes to interact with the program.Moving the mouse, typing your name, or clicking a button. Action / ResponseWhat the program does *after* an event is triggered. It's the 'reaction' to the user's input.An event is 'clicking a door'. The...
3

Core Syntax & Patterns

The 'When... Do...' Pattern WHEN [a specific event happens], DO [a specific action]. This is the most basic and important pattern. You use it to connect a trigger (the event) to a response (the action). Every interactive part of your story will use this pattern. The Conditional Event Pattern WHEN [event happens], IF [a condition is true], THEN DO [Action A], ELSE DO [Action B]. Use this to make events smarter. Instead of the same thing happening every time, the program can check a condition (like if a variable is a certain value) and decide between two different actions. The Broadcast Pattern WHEN [event happens], broadcast [message]. THEN, WHEN I receive [message], DO [another action]. This is how you make one event trigger another event, even on a differe...

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
You're designing a mystery story with 3 possible endings. The ending depends on whether the player found the 'letter' and whether they accused the 'butler'. Which set of variables and events is BEST to manage this?
A.One variable `ending_number`. Set it to 1, 2, or 3 when the player does something.
B.Three separate events: `WHEN ending_1_triggered`, `WHEN ending_2_triggered`, `WHEN ending_3_triggered`.
C.Variables for `story_progress` and `player_choice` that are checked by a single 'End Story' event.
D.Two boolean variables: `found_letter` and `accused_butler`. An event at the end of the game checks these variables to decide the ending.
Challenging
In computer science, we can represent `true` as 1 and `false` as 0. A door is locked. We have a variable `door_locked = 1`. An event `WHEN key is used on door` runs this code: `SET door_locked = 0`. Another event `WHEN monster touches door` runs this code: `IF door_locked == 0, THEN monster enters`. If the player uses the key and then the monster touches the door, what happens?
A.The monster cannot enter because `door_locked` is 1.
B.The monster enters because using the key set `door_locked` to 0.
C.The monster enters because `door_locked` is always 0.
D.An error occurs because you can't compare a variable to 0.
Challenging
When a player clicks a 'magic rain' button, you want 100 raindrops to appear at random spots. Which is the most effective code for the button's event handler?
A.REPEAT 100 TIMES { CREATE clone of raindrop at random position }
B.CREATE clone of raindrop. WHEN raindrop is created, CREATE clone of raindrop.
C.Have 100 separate raindrop sprites and a `WHEN button clicked, SHOW` command for each one.
D.WHEN button clicked, SET raindrop_count = 100.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Event-Driven Programming: Making Things Happen

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.