Learning Goals 3 min
By the end of this lesson you will be able to:
- Use show variable [score v] and hide variable [score v] to control the on-Stage watcher from your script (not just the checkbox in the palette).
- Right-click a watcher on the Stage and switch between the three modes: normal readout, large readout, and slider.
- Use a slider watcher as an input — the player drags it, and your script reads the new value with the round reporter (score).
Warm-Up — the box you've been ignoring 7 min
Open the project you saved as homework last lesson — the two-variable game with score and lives. Look at the top-left corner of the Stage. You should see two little grey boxes:
when flag clicked
set [score v] to (0)
set [lives v] to (3)
Those boxes are called variable watchers. They've been there the whole time. You probably ticked them once and forgot. But they're not just decoration — they have three modes, and one of them turns them into a slider the player can drag.
Reveal: what can you do with a watcher?
Three things. One, drag it anywhere on the Stage to position it nicely (top-right for score, top-left for lives — your choice). Two, right-click it to change how it looks — normal grey box, big blue number, or a slider. Three, control whether it's visible from inside your scripts using show variable and hide variable. Today covers all three.
Today we'll stop ignoring those little boxes and start using them — to make the game look better, to surprise the player, and (the cool one) to let them change a number with the mouse.
New Concept — the watcher, three modes, two blocks 15 min
A variable watcher is the little box on the Stage that shows a variable's current value. Every variable you make gets one, and every watcher starts off ticked-on (visible). You can hide it with the checkbox in the Variables palette — or, much more usefully, from inside a script.
Show and hide from inside a script
Two orange blocks at the bottom of the Variables palette do this:
show variable [score v]
hide variable [score v]
Why script it instead of just clicking the checkbox? Because games have moments. The score should hide on the title screen and appear when the game starts. The lives counter should hide on the win screen. The "secret bonus" variable should stay hidden until the player finds it.
when flag clicked
hide variable [score v]
hide variable [lives v]
wait (2) seconds
show variable [score v]
show variable [lives v]
The three watcher modes
Right-click (or two-finger tap on a trackpad) on any watcher on the Stage. A small menu opens with three options at the top:
- normal readout — the default. A small grey box with the variable's name on the left and its value on the right. Good for most things.
- large readout — a big bright orange box with just the value, no name. Good for "the score" in an arcade game where you want the number to be huge.
- slider — adds a draggable handle under the value. The player can drag it to change the variable's value while the game runs.
You don't switch modes from a block. Modes are a property of the watcher itself, set by the right-click menu, and they stay set across runs and saves.
The slider is the magic one
Switch a watcher to slider mode. A horizontal bar with a draggable circle appears under the number. The player can grab that circle and slide it — and as they slide, the variable's value updates in real time.
That means your script can read what the player has chosen using the round reporter:
when flag clicked
forever
set [size v] to (cat-size)
end
cat-size slider on the Stage. The cat's size changes live. (Assumes you've made a variable called cat-size and set its watcher to slider mode.)You can also set the slider's min and max. Right-click the slider again and pick change slider range — type a min (like 10) and a max (like 200). The slider won't go beyond those.
Worked Example — Priya's resize-the-cat slider 12 min
Priya wants a tiny project where the player can drag a slider to grow and shrink the cat in real time. We'll build it in eight steps using just one variable and the slider mode.
cat-size watcher, switched to slider mode, becomes a control the player can drag.Step 1 — Start fresh
New Scratch project. Default cat in the middle of the Stage.
Step 2 — Make the variable
Variables palette → Make a Variable → type cat-size → OK. A watcher appears on the Stage showing cat-size 0.
Step 3 — Set a sensible starting value
On the cat, drop this stack:
when flag clicked
set [cat-size v] to (100)
Step 4 — Switch the watcher to slider mode
Right-click the cat-size watcher on the Stage. From the menu, pick slider. The watcher grows a draggable handle below the number.
Step 5 — Set the slider range
Right-click the slider again. Pick change slider range. Type minimum 10, maximum 200, OK. Now the slider can't go bigger than 200% or smaller than 10%.
Step 6 — Make the cat's size follow the variable
Add this second stack on the cat:
when flag clicked
forever
set size to (cat-size) %
end
Step 7 — Click the flag and drag
Click the green flag. Drag the slider on the Stage. The cat grows and shrinks live. That's it — the player is now interacting with your game without touching a key or moving the mouse around the sprites.
Step 8 — Add a hide-and-show flourish
Make the slider disappear for the first second of each run, like a little dramatic reveal:
when flag clicked
hide variable [cat-size v]
set [cat-size v] to (100)
wait (1) seconds
show variable [cat-size v]
The full assembled cat-sprite scripts
when flag clicked
hide variable [cat-size v]
set [cat-size v] to (100)
wait (1) seconds
show variable [cat-size v]
when flag clicked
forever
set size to (cat-size) %
end
What you just built: a Scratch project with a real input control — the player changes a number with the mouse and the sprite responds instantly. That's the same idea behind volume sliders, brightness sliders, and game-difficulty sliders in every app on your phone.
Try It Yourself — three watcher drills 15 min
Goal: Make a variable called secret and set it to 42 at the flag. Hide its watcher at the start. When the space key is pressed, show it for one second, then hide it again.
when flag clicked
set [secret v] to (42)
hide variable [secret v]
forever
if <key [space v] pressed?> then
show variable [secret v]
wait (1) seconds
hide variable [secret v]
end
end
Think: The watcher is a thing you can flash on and off, like a sprite. Show and hide are the variable-watcher version of show and hide for sprites.
Goal: Make a variable called volume. Switch its watcher to slider mode with range 0–100. Add a sprite that plays a drum every second using play drum (1 v) for (0.25) beats, and make its drum-loudness controlled by the slider via set volume to () %.
when flag clicked
set [volume v] to (50)
forever
set volume to (volume) %
play drum (1 v) for (0.25) beats
wait (0.75) seconds
end
Think: The sound's volume input is just a number — and the slider gives the player a number. The variable is the bridge between them. Same pattern as the cat-size example, different output.
Goal: Two sliders, two effects. Make variables spin-speed (range 0–30) and cat-colour (range 0–200). The cat should turn by the spin-speed every frame, and have a colour effect set to cat-colour every frame. Player drags both sliders and the cat goes wild.
when flag clicked
set [spin-speed v] to (5)
set [cat-colour v] to (0)
forever
turn cw (spin-speed) degrees
set [color v] effect to (cat-colour)
end
Think: Two sliders on the Stage at the same time — each one drives a different effect, totally independently. You've made a tiny art toy. Future-you in Level 3 will use this exact pattern to make settings panels for your games.
Mini-Challenge — the slider that does nothing 5 min
"Why doesn't Daniel's cat get bigger?"
Daniel made a variable called cat-size, switched its watcher to slider mode with range 10–200, and wrote this:
when flag clicked
set [cat-size v] to (100)
set size to (cat-size) %
Daniel drags the slider all the way to 200, but the cat stays at 100%. Why? What's missing?
Reveal the bug and the fix
The size-setting block runs once — right when the flag is clicked. After that, the script ends. The cat's size is set to cat-size (which is 100) and Scratch never looks at the slider again. Daniel can drag the slider all afternoon and the variable will update, but no block is ever re-reading it.
The fix is to wrap the size-setting block in a forever loop so it re-reads every frame:
when flag clicked
set [cat-size v] to (100)
forever
set size to (cat-size) %
end
One extra block — the forever — and the cat now follows the slider live. A slider on the Stage is useless without a script that re-reads the variable. The slider writes, your forever reads.
Recap 3 min
You met the variable watcher properly. Every variable in your project has a little box on the Stage that shows its current value. Tick or untick its checkbox in the palette to toggle it, or — more powerfully — use show variable and hide variable blocks to control it from a script. Right-click any watcher to switch between normal, large, and slider modes. The slider mode turns the watcher into a player input — they drag, the variable updates, and a forever loop in your script can read the new value and do something with it.
- Variable watcher
- The little box on the Stage that shows a variable's current value. Created automatically for every variable you make, and toggled by the checkbox in the Variables palette.
- Show / hide variable
- The two blocks show variable [ v] and hide variable [ v] at the bottom of the Variables palette. They control the watcher's visibility from inside scripts — useful for title screens, end screens, and surprises.
- Slider mode
- A watcher display mode (right-click → slider) that lets the player drag a handle to change the variable's value while the game runs. Set the allowed range with the change slider range menu item.
- Read-the-variable loop
- The pattern of putting (name) inside a block (like set size to ()) and wrapping the whole thing in a forever, so the sprite re-checks the variable many times a second.
Homework 2 min
The Music-Box Slider. Build a one-sprite project where the player controls a sound effect with two sliders.
- Make two variables: pitch-shift (range −50 to 50) and beat-speed (range 0.1 to 2).
- Right-click each watcher and switch both to slider mode. Set the ranges above.
- Reset both variables at the flag: set [pitch-shift v] to (0) and set [beat-speed v] to (1).
- Add a forever loop: set [pitch v] effect to (pitch-shift), then play drum (1 v) for (0.25) beats, then wait (beat-speed) seconds.
- Add a third script: when the down arrow is pressed, hide variable [pitch-shift v] and hide variable [beat-speed v]. When up arrow, show both again.
Save as HW-L2-32-Music-Box.sb3. Click the flag and drag the sliders while the drum plays. Press down to hide them, up to show them.
Bring back next class:
- The
.sb3file. - Your answer to: "What happens if you set the slider range backwards (max smaller than min)? Try it and write one sentence about what you see."
Heads up for next class: SCR-L02-33 is about naming your variables well. You'll see why cat-size is a great name and why x, var1, and score2 are terrible ones — and how a good name today saves you (and your teacher) ten minutes of head-scratching tomorrow.