Skip to content
Computing · Year 5 · Variables in Games · Spring Term

Introducing Variables

Learning how to create placeholders for data that changes during a program's execution.

National Curriculum Attainment TargetsKS2: Computing - Programming and Algorithms

About This Topic

This topic introduces variables as named containers for data that can change while a program is running. Students learn to define a variable (give it a name) and initialise it (give it a starting value). This is a core concept in the UK National Curriculum for Key Stage 2, where students are expected to use variables in their programs.

In Year 5, the focus is on understanding that a variable is a placeholder. Whether it is a score in a game, a timer, or a player's name, the variable allows the program to be dynamic. Mastering this concept is essential for moving beyond simple linear scripts to creating interactive games and simulations.

Students grasp this concept faster through hands-on modeling where physical containers represent the variables in a program.

Key Questions

  1. Justify why we must set a variable to a starting value at the beginning of a game.
  2. Explain how one variable can be used to control multiple different sprites.
  3. Critique the impact of a confusing or inaccurate variable name on a program.

Learning Objectives

  • Identify the purpose of a variable as a named container for data that can change.
  • Demonstrate how to initialise a variable with a starting value in a simple program.
  • Explain how changing the value of a variable affects the output or behaviour of a program.
  • Critique the choice of variable names in provided code snippets for clarity and accuracy.

Before You Start

Sequencing Instructions

Why: Students need to understand that programs follow a specific order of instructions before they can grasp how variables change within that sequence.

Basic Program Logic

Why: Familiarity with simple conditional statements (if/then) helps students understand how variable values can trigger different program behaviours.

Key Vocabulary

VariableA named storage location in a computer program that holds a value. This value can change while the program is running.
InitialiseTo set a variable to a specific starting value before it is used in a program. This ensures the program begins with predictable data.
Data TypeThe kind of data a variable can hold, such as a number (integer or decimal) or text (string).
AssignThe action of giving a value to a variable, either when it is first created or later in the program.

Watch Out for These Misconceptions

Common MisconceptionA variable can hold multiple different values at the exact same time.

What to Teach Instead

Explain that a variable is like a single seat on a bus; only one value can sit there at a time. When a new value arrives, the old one is replaced. Physical modeling with boxes and single items helps reinforce this 'overwrite' rule.

Common MisconceptionThe name of the variable affects what it can do.

What to Teach Instead

Clarify that naming a variable 'score' doesn't automatically make it count points; the programmer must write the logic. Students often think the computer 'understands' English words, so showing a program where a variable named 'bananas' stores the score can be a powerful lesson.

Active Learning Ideas

See all activities

Real-World Connections

  • Video game developers use variables to keep track of player scores, health points, and the number of lives remaining. For example, in a racing game, a 'lap count' variable increases with each completed lap.
  • App designers use variables to store user preferences, such as theme colours or notification settings. A weather app might use a variable to store the current temperature, which updates automatically.

Assessment Ideas

Quick Check

Present students with a short, simple program snippet that uses a variable (e.g., a score counter). Ask them to identify the variable name, its initial value, and predict the value after a specific action occurs. For example: 'What is the value of 'score' after the player collects 3 coins?'

Discussion Prompt

Pose the question: 'Imagine you are designing a game where a character needs to jump. What variable could you use to control the height of the jump? Why is it important to give this variable a starting value?' Listen for student explanations of variables as placeholders and the need for initialisation.

Exit Ticket

Give each student a slip of paper. Ask them to write down one example of a variable they might use in a game and explain in one sentence why they chose that particular name for it. Collect and review for understanding of variable purpose and naming conventions.

Frequently Asked Questions

Why do we have to 'initialise' a variable?
Initialising sets a starting point. If you don't tell a game to start the score at 0, the computer might start with a random number or an error. It ensures the program behaves predictably every time it starts. Think of it like resetting a board game before you begin playing.
Can a variable store words as well as numbers?
Yes! Variables can store different types of data. A 'string' variable stores text (like a player's name), while an 'integer' variable stores whole numbers (like a score). In Year 5, we mostly focus on numbers, but it is good to know they can hold names too.
How does student-centered learning help with programming concepts like variables?
Programming can feel abstract and intimidating. Student-centered approaches, like 'unplugged' role plays, allow students to physically manipulate the logic before they ever touch a keyboard. By acting as the computer and managing 'variable boxes', students build a mental model of data storage that makes the transition to screen-based coding much smoother and more intuitive.
What is the best way to name a variable?
A good variable name should be descriptive and use underscores or 'camelCase' instead of spaces (e.g., 'player_health' or 'playerHealth'). This makes the code much easier for humans to read and debug later on. Avoid using single letters like 'a' or 'b'.