Variables in Scratch

    Atul Kabra4 min readUpdated
    मराठीत वाचा

    A variable in Scratch is a labelled box that remembers a number or a word so your child's project can use it later. The most common use is keeping score in a game. When a child makes a variable called "score" and adds one to it each time the player wins a point, they are using a variable. This guide explains the idea simply and shows how to make and use one.

    What is a Variable?

    Picture a small box with a label on it. You can put one thing inside, take it out, change it, or look at it whenever you want. A variable is exactly that: a named container that holds a value.

    In Scratch, the value is usually a number, like a score or a count of lives, but it can also be a word, like a player's name. The lovely thing is that the value can change as the project runs. The score starts at zero, then grows as the player succeeds. That changing-ness is why it is called a "variable."

    Making a Variable

    Variables live in the Variables group, coloured orange. To make one:

    1. Click the Variables group in the palette.
    2. Click the "Make a Variable" button.
    3. Type a clear name, such as "score" or "lives."
    4. Click OK.

    Straight away, your child sees a small display appear on the stage showing the variable and its current value, like "score 0." Several new blocks also appear, ready to use.

    Using a Variable to Keep Score

    Here is the most rewarding use for children. Once a "score" variable exists, these blocks become available:

    • "set score to 0" — used at the start to reset the score.
    • "change score by 1" — used to add a point.
    • A small round "score" block — used to check the value inside a condition.

    A simple scoring recipe:

    1. At the green flag, add "set score to 0" so every game begins fresh.
    2. Inside a forever loop, add an if-then: "if touching coin, then change score by 1."
    3. Watch the score on the stage tick upward as the player collects coins.

    Children adore seeing that number climb. It turns a bit of movement into a real game with a goal.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses

    Other Friendly Uses

    Variables can hold all sorts of useful things:

    • Lives: Start "lives" at 3, and "change lives by -1" whenever the player is hit. When lives reach 0, end the game.
    • Timers and counters: Count how many times something has happened.
    • A name: Ask the player their name and store it, then have a sprite greet them by name. This usually pairs with an "ask and wait" block from the Sensing group, which stores the player's answer.

    Showing and Hiding Variables

    Your child can choose whether a variable's box appears on the stage. The Variables group has "show variable" and "hide variable" blocks. A score is usually shown so players can see it, while a behind-the-scenes counter might be hidden to keep the stage tidy. There is also a checkbox beside each variable in the palette that toggles its display.

    Tips for Parents

    • Name variables clearly. "score" and "lives" are far easier for a child to follow than "x" or "thing1." Good names make the code read like a story.
    • Always reset at the start. Building the habit of "set score to 0" at the green flag prevents the confusing bug where the score keeps growing across games.
    • Relate it to a scoreboard. "It's like the scoreboard at a cricket match. The number changes as runs are scored." Familiar comparisons help.

    Common Mistakes

    • Forgetting to reset. If the score does not start at zero each game, add a "set score to 0" block under the green flag.
    • Using "set" when you mean "change." "Set score to 1" forces it to 1 every time, wiping previous points. "Change score by 1" adds on top of what is there. This is a very common mix-up worth gently pointing out.
    • Variable on the wrong sprite. When making a variable, Scratch asks "for all sprites" or "for this sprite only." For a shared score, "for all sprites" is usually what you want.

    Frequently Asked Questions

    Can a variable hold words, not just numbers? Yes. A variable can store a word or sentence, such as a player's name, just as easily as a number.

    What is the difference between "set" and "change"? "Set" replaces the value with a fixed number. "Change" adds to (or subtracts from) the current value. Use "set" to reset, "change" to score.

    What's Next?

    Variables become truly powerful once your child combines everything. Read Conditionals (If-Then) in Scratch to make decisions based on a score, then put it all together with Make Your First Scratch Game. Browse the full set on the kids' Scratch hub.

    For warm, guided lessons that bring these ideas together, see our Scratch & Coding for Kids program in Jalgaon. Join the waitlist for the next batch.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses
    Atul Kabra

    Founder, Infoplanet

    Atul Kabra founded Infoplanet in 2001 and has spent over two decades teaching programming — C, C++, Java, databases and more — to students across Maharashtra.

    Related guides