Introduction
In this Hour of Code lesson, students will create an interactive fantasy story that stars the player as the hero. They’ll code a text box to ask the player for their name, choose a magical item, and set a character role based on that choice. Using text variables, click events, and template-based storytelling, students will design a short adventure that changes based on player input—building both creativity and coding skills.
Objectives
Students will:
- Understand how to create and use text variables to store player input.
- Use template variables (e.g., {{name}} and {{role}}) to personalize story content.
- Apply event-driven coding using blocks like <code class="events">On Click</code> and <code class="events">On Page Start</code> to change story outcomes.
- Design an interactive experience that combines creative storytelling with basic coding logic.
Coding Concepts Covered
Function in Parallel User Input Field Text VariableStudent Instructions
Use the Create Text Variable block to make a new variable called name
for the player’s name.
Ask the player to type their name in the text box, then save it in the name
variable.
Give the player a starting role before they choose anything. Use the Create Text Variables
block to create and name a variable called role
.
✏️ You’ll use this later in a sentence like:
"This is the beginning of {{name}}’s adventure as {{role}}."
Let the player choose a magical item to change their role.
Curly brackets like {{name}} or {{role}} are special placeholders. They tell the computer:
👉 Put the value of this variable here.
Try it out: This is the beginning of {{name}}’s adventure as {{role}}.
💡 Ideas to try:
✍️ Continue the story: What happens next in your hero’s adventure?
🧭 Add buttons to let the player explore different paths using the Go To Page
block.
🎵 Add background music with the Play Music
block to match the mood.
🖼️ Include more images or backgrounds to bring your fantasy world to life.
Interactive Project Example for Students
Play through this lesson's example project created on Elementari. Use this example to guide and motivate your students.