NEW Explore the Scratch Block Dictionary, tutorials, textbook, and classroom guides

Start learning →

Chapter 9: Variables (Memory & State)

📌 What you will learn

Store changing values—score, lives, speed, and game state—and master proper initialization and scope.

Lesson goal & core concept

Initialize variables reliably and choose between global ("for all sprites") and local ("for this sprite only") variables.

Think of a variable as a labeled box. "set" replaces what is inside; "change" adds or subtracts from what is already there.

INTERACTIVE LAB

Variable & List Visualizer (1-Indexed Scratch Lists)

Click the Scratch data operations below to watch variables update and see how Scratch 1-indexed list items shift when you add, insert, or delete.

Variable: score 0
Ready: click any variable or list button
List: inventory length: 3

    Step-by-step practice

    Work through these steps in the Scratch editor, predicting each result before clicking the green flag.

    • Create a score variable and reset it to 0 under the green flag.
    • Increment score when collecting a star, with a short wait or hide so it counts once.
    • Use a "state" variable ("title", "playing", "gameover") to control phases.
    • Use local variables when each clone needs its own HP or speed.
    Chapter 9: Variables (Memory & State) — Example
    1. When green flag clicked
    2. Set score to 0
    3. Set lives to 3

    Try it: Starts every game cleanly with fresh counters.

    Mini challenge & next steps

    Swap the values of two variables A and B using a third temporary variable "temp".

    Scratch Learning Textbook Home Return to the full 4-stage curriculum overview. Learn more → Scratch Block Dictionary Look up any block used in this chapter. Learn more →

    FAQ

    How long should I spend on "Chapter 9: Variables (Memory & State)"?

    Aim for 15–20 minutes: read the concept, test the small example, modify one value to see what changes, and try the mini challenge.

    This guide is provided for educational purposes. Scratch screens and terms may change over time, so please check the official Scratch website as well.