How to Use Variables in Scratch | Variable Blocks in Scratch | Complete Tutorial

How to Use Variables in Scratch Variable Blocks in Scratch Complete Tutorial

Introduction: Variable Blocks in Scratch

Whether you’re just getting started with Scratch programming or looking to take your projects to the next level, understanding variables and lists is crucial. These powerful tools let you store, manage, and manipulate data — making your games and animations smarter, more dynamic, and interactive.

In this beginner-friendly guide inspired by Kodex Academy’s Scratch tutorial video, you’ll learn:

  • How to use variables in Scratch
  • How to create a variable in Scratch and apply it
  • How to create and manage lists in Scratch
  • Practical use cases of variable blocks and list blocks
  • Tips to make Scratch games more interactive using variables
  • Enhancement features and ready-to-use code snippets

What Are Variables in Scratch

A variable in Scratch is a storage container for a single piece of data at a time—it could be a number, a word (text/string), or boolean‑like (true/false) values. Scratch provides built‑in capability to:

  • Create a variable
  • Set its value
  • Change its value
  • Show or hide the variable on the screen (monitor it)
  • Use the variable’s value in calculations, comparisons, game logic, etc.

There is always a default variable (“my variable”) present, as explained in the transcript.

Scratch variables are usually of two types:

  • Global variable (“For all sprites”): accessible by all sprites and the stage
  • Local / sprite‑only variable (“For this sprite only”): accessible only within one sprite. en.scratch-wiki

Also, Scratch supports cloud variables, which are global variables stored on Scratch’s servers, sharing state across users or project instances. However, there are limitations (e.g. only numeric, update rates, etc.). en.scratch-wiki

How to Create and Use Variables in Scratch

Based on the Kodex Academy transcript, here are step‑by‑step ways to use variables in Scratch, with added tips and code blocks.

Creating a Variable

  1. Click the Variables block palette (orange color).
  2. Choose Make a Variable.
  3. Type a name (for example, score, playerName, lives). Make it descriptive.
  4. Choose scope: For all sprites (global) or For this sprite only (local).
  5. Press OK. The variable appears in the variable palette as well as a checkbox to show/hide it on the stage.

Tip: Use meaningful names (playerScore, livesLeft) rather than generic ones—helps when your project gets larger.

Basic Variable Blocks

After creating a variable, some of the most commonly used blocks are:

  • set [variable] to (value) — sets the variable to a specific value.
  • change [variable] by (value) — increases or decreases the variable by a value.
  • show variable [variable] — displays the variable monitor on stage.
  • hide variable [variable] — hides the monitor.
  • (variable) — reports/returns the current value.

Example: Reset Score on Game Start

Suppose you have a game where you want the score to start at zero each time the game starts. You could script:

when green flag clicked
set [score v] to (0)

Example: Increase Score When Collecting an Object

when this sprite clicked
change [score v] by (1)

Example: Hide / Show Score

when green flag clicked
hide variable [score v]

// Later in game, say when level begins
show variable [score v]

What Are Lists in Scratch

A list is like a variable but can contain multiple items (text, numbers). You can think of it as an array or group of values. Lists are great when you need to manage collections: names, days, levels, scoreboard entries, inventories, etc.

List blocks in Scratch allow you to:

  • Create a list
  • Add items to it
  • Delete items
  • Insert at position
  • Replace items
  • Find the length (number of items)
  • Check if list contains a particular item
  • Show or hide the list on the stage

Using Lists – Step by Step

Using the transcript’s scenarios, here’s what to do:

  1. Click Variables palette → Make a List.
  2. Name it (e.g. Weekdays, Inventory, HighScores).
  3. The list appears in the palette. You’ll see list‑related blocks appear (add, delete, length, etc.).

Adding Items

when green flag clicked
add [Monday] to [Weekdays v]
add [Tuesday] to [Weekdays v]
add [Wednesday] to [Weekdays v]

Deleting Items

// delete first item
when green flag clicked
delete (1) of [Weekdays v]

// delete all items
delete all of [Weekdays v]

Checking If an Item Exists

contains [Weekdays v] [Monday]

Find Length of the List

length of [Weekdays v]

Hide / Show List

show list [Weekdays v]
hide list [Weekdays v]

Full Example: Making a Simple Game with Variables and Lists

Let’s imagine a quiz game. You want to:

  • Keep track of the player’s score
  • Keep a list of questions used (so you don’t repeat them)

Here’s a skeleton script for one sprite (“QuizMaster”) and the Stage:

// At start
when green flag clicked
set [score v] to (0)
delete all of [UsedQuestions v]
show variable [score v]
show list [UsedQuestions v]

// Question loop
repeat until <(number of questions answered) = (total questions)>
    ask [What is 2 + 2?] and wait
    if <(answer) = [4]> then
        change [score v] by (1)
        say [Correct!] for (2) secs
    else
        say [Oops!] for (2) secs
    end
    add [What is 2 + 2?] to [UsedQuestions v]
end

// After quiz
say (join [Your final score is ] (score))

This uses variables (score) and list (UsedQuestions) together to build an interactive game.

Additional Scenarios & Use‑Cases

  • Timer or Countdown: Use a variable timeLeft, decrement every second, show it on screen.
  • Lives System: Variable lives set to some initial number; change by ‑1 when hit, if 0 then game over.
  • Inventory in Adventure Games: Use list to store items the player collects.
  • High Score List: Sort or maintain a list of top scores; use add, delete, length, etc.
  • Dynamic names: Use variables to store player name or inputs, then use in dialogues.

Enhancement Features & Advanced Code Ideas

To go beyond basics, here are enhancements you can add, with code templates:

1. Cloud Variables for Leaderboards

Using cloud variables, you can store high scores or global stats that persist across sessions and are visible to others.

// Only numeric values allowed in cloud variables
when green flag clicked
set [cloudHighScore v] to (0) // Cloud variable set in creation dialog

Then you can compare and update if the player beats the previous high score.

2. Dynamic Difficulty Adjustment

Use variables to adjust how hard the game gets:

when green flag clicked
set [score v] to (0)
set [difficulty v] to (1)

forever
  wait (5) seconds
  change [difficulty v] by (1)
end

// When spawning enemies, use difficulty
spawnEnemy
  set speed to (difficulty * 2)

Using Lists for Randomized Content

To avoid repetition, you can pick random items from a list and then remove them to ensure uniqueness:

when green flag clicked
delete all of [Questions v]
add [Q1] to [Questions v]
add [Q2] to [Questions v]
add [Q3] to [Questions v]
// etc.

repeat until <(length of [Questions v]) = (0)>
   set [index v] to (pick random (1) to (length of [Questions v]))
   set [currentQuestion v] to (item (index) of [Questions v])
   // ask currentQuestion etc.
   delete (index) of [Questions v]
end

Improved UI / Display

  • Show/hide variable monitors depending on game state (intro vs gameplay).
  • Use large readout monitors for important variables like timer or lives.
  • Use the slider monitor for variables that change within a range (e.g. volume settings etc.).

Animations or Interactive Effects Controlled by Variables

For example: control sprite size, color, speed based on variable value.

when green flag clicked
set [speed v] to (5)
forever
  move (speed) steps
  wait (0.1) seconds
  if <key [up arrow] pressed?> then
     change [speed v] by (1)
  end
  if <key [down arrow] pressed?> then
     change [speed v] by (-1)
  end
end

Troubleshooting & How to Avoid Errors

  • Using vague variable/list names → choose names that reflect purpose (score, health, inventory).
  • Forgetting to reset variable or list at start (on green flag) → causes unexpected behavior.
  • Showing too many variables or lists on screen → may clutter your stage. Use show/hide appropriately.
  • Using wrong scope (sprite vs all sprites) → some sprites won’t access local variables of others.

Conclusion

Mastering variables and lists in Scratch is a game-changer when it comes to creating engaging, interactive, and smart projects. Whether you’re building a Scratch game, developing a quiz, or working on a creative animation, understanding how to create a variable in Scratch or manage a list opens up endless possibilities.

In this tutorial, we’ve covered:

  • ✅ What variables are and how they store data like scores, names, or any numeric value.
  • ✅ How to use essential variable blocks such as set, change by, show, and hide.
  • ✅ How to create a list in Scratch and use list blocks to add, delete, search, and manage multiple data entries.
  • ✅ Practical code examples that help you build smarter logic into your Scratch programs.
  • ✅ Enhancement tips to take your projects from beginner to pro level.

Whether you’re just starting or aiming to create advanced games in Scratch, working with variables and lists is the key to unlocking the full potential of Scratch programming.

Call to Action

  1. Don’t forget to check out the full video tutorial: How to Use Variables in Scratch | Variable Blocks Tutorial in Scratch – Kodex Academy
  2. Like, comment & share the video
  3. Visit kodexacademy.com
  4. subscribe to the Kodex Academy YouTube channel for deeper Scratch content.

Happy coding with Kodex Academy! 🚀

Learn More with Kodex Academy

At Kodex Academy, we’re passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.

Explore more:

Stay updated with new content, free tutorials, and coding challenges!

Further Reading & Links

Recent Posts

How to Make a Math Racing Game in Scratch | Game Concepts and Complete Tutorial

In this tutorial, you’ll learn to build a Math Racing Game in Scratch. Players solve math problems to move their character forward; wrong answers benefit the opponent. It’s a race of speed, accuracy...

How to make Memory Skill Game in Scratch | Card Matching Game in Scratch – Part 2 | Step-by-Step Coding

In this tutorial you'll learn how to make memory skill game in Scratch / card matching game in Scratch. This is a great beginner‑to‑intermediate project for scratch tutorial game, scratch programming...

How to make a Card Matching Game in Scratch | Memory Skill Game in Scratch – Part 1 | Step-by-Step Coding

In this Scratch tutorial, we'll walk you through how to make a card matching game in Scratch, also known as a memory game or skill game. This is a popular beginner project that introduces essential...

Create a Quiz Game in Scratch | Spelling Test in Scratch | Picture Identification in Scratch

Want to make learning spelling fun, visual, and interactive? In this Scratch tutorial, you'll learn how to make a spelling quiz game in Scratch using picture identification, text-to-speech, and...

How to make a Double Jump Game in Scratch | Platformer game in Scratch | Step by Step Coding

How to make a Double Jump Game in Scratch. Scratch is a fantastic platform for beginners to learn programming by making games, animations, and interactive stories. Among the many kinds of games...

How to Use Variables in Scratch | Variable Blocks in Scratch | Complete Tutorial

Introduction: Variable Blocks in Scratch Whether you’re just getting started with Scratch programming or looking to take your projects to the next level, understanding variables and lists is...

How to Make Earth Revolve Around the Sun in Scratch: A Complete Tutorial & Enhancements

Animating Earth revolving around the Sun is a classic beginner/intermediate Scratch animation project. It combines trigonometry (sine & cosine), variables, loops, and visual scripting. Kids can learn...

How to Make a Game in Scratch | Snake Game in Scratch | Step-by-Step Game Coding

In this tutorial, we’ll build a Snake Grid style game in Scratch step by step (very similar to the Kodex Academy example). By doing this, you’ll cover many of the core Scratch building blocks. We will...

How to Use Operator Blocks in Scratch | Full Guide with Live Coding & Examples

One of the most powerful features in Scratch is its Operator Blocks — essential for handling math operations, logic comparisons, and string manipulations...

How to Create a Thirsty Crow Story in Scratch | Animation Story in Scratch for Kids

In this tutorial, you’ll learn how to create the classic “Thirsty Crow” story in Scratch, using simple animation, voice, and sprite actions. This is a perfect project for kids who are new to coding...

How to Create a Dodge Ball Game in Scratch: A Complete Step-by-Step Tutorial for Beginners

This step-by-step tutorial will guide you through how to create a Dodge Ball game in Scratch from scratch! In this game, you’ll control a character trying to dodge falling balls, earn points, and...

How to use Sensing Blocks in Scratch | Scratch programming for beginners | Live Coding with Examples

In today’s session, we’re diving deep into one of the most powerful features of Scratch — Sensing Blocks. These blocks allow your projects to interact with the world, detect touches, respond to...

Build an Egg Shooting Game in Scratch: Step-by-Step Coding | Complete Guide for Beginners

Learn how to create a fun, interactive shooting game in Scratch with this detailed tutorial inspired by classic arcade games. Perfect for kids and beginners looking to dive into Scratch programming!...

How to Make a Maze Game in Scratch | Step by Step Coding | Full Tutorial & Enhancements

Introduction: Why Build a Maze Game in Scratch? If you’re looking for a Scratch beginner project idea that’s fun, interactive, and educational, then building a maze game in Scratch is the...

Scratch Control Block Tutorial: Full Guide with Loops, Conditions, Cloning & Code Examples

“Control blocks” in Scratch are those blocks (from the Control category) that manage the flow of your script: when things happen, how many times they happen, making decisions, repeating actions...

How to Create a Car Racing Game in Scratch – Part 2 – Step-by-Step Coding

Welcome to your ultimate guide on how to make a car racing game in Scratch—a step‑by‑step tutorial. You'll learn Scratch game development techniques, see actual code blocks, and discover enhancements...

How to Make a Hurdle Jumping Game in Scratch – Build a Fun Hurdle Runner with Score & Win Screen

Are you ready to create your very own hurdle jumping game in Scratch—just like the iconic Chrome Dino or Super Mario? 🎮 Whether you're new to Scratch or just looking for your next fun project, this...

How to Create a Car Racing Game in Scratch – Part 1 – Step-by-Step Coding

In this Scratch car racing game tutorial, we’ll walk you through how to create a fully functional, visually exciting, and incredibly fun car racing game using Scratch. In this blog, we’ll cover: How...
Scroll to Top