Learning Goals 3 min
By the end of this lesson you will be able to:
- Explain the difference between a variable (holds one value) and a list (holds many values in order).
- Use the words item and index correctly, and remember that Scratch indexes start at 1, not 0.
- Find the Make a List button in the Variables palette, create a list called
shopping, and read its watcher widget on the Stage.
Warm-Up — the long-suffering variable 7 min
Imagine your teacher wants Scratch to remember the names of every student in your class — maybe 30 names. Using only what you know so far (variables), how would you store them?
Reveal the answer
You'd be stuck making 30 separate variables: student1, student2, student3… all the way to student30. To print them all you'd need 30 say blocks. To add a new student you'd need a new variable. To remove one you'd have a gap. Painful, ugly, doesn't scale.
This is exactly the problem lists solve. A list is one named thing that holds many values, in order, and grows or shrinks on demand.
Quick second puzzle — and our first peek at the Shopping List Helper. Look at this Saturday-market shopping list Mak wrote on the fridge:
If Mak says "grab item number 3", what should you buy? And if she adds "santan" to the bottom of the list, what is its number?
Reveal the answer
Item 3 is bawang merah. The new item santan becomes item 6 (it goes at the bottom). Notice we counted starting from 1, not 0 — exactly like Scratch lists. The position number of an item in a list is called its index. You'll hear that word a lot in the next seven lessons.
New Concept — variables vs lists 15 min
Every variable you've made so far has held exactly one value — one number, one word, one yes/no answer. You can change the value, but you only ever have one at a time. A variable is like a single box with the variable's name written on the front.
One box vs a row of boxes
A list is a row of numbered boxes that all share one name. The list's name (say shopping) is the row's name. Inside the row, each box has its own number — its index. Boxes hold items.
(score)
Compare that to how a list shows on the Stage. You won't build one yet — just look at the shape:
shopping 1 Roti 2 Telur 3 Bawang merah 4 Cili 5 Ais krim length 5
The list watcher widget that Scratch draws on the Stage when you tick a list's box. Notice the name at the top, the numbered rows in the middle, and the length at the bottom.
Three words you must remember
- List — the whole row of boxes, with one name.
- Item — what's inside one box. Items can be numbers, words, even whole sentences.
- Index — the position number of a box. Scratch indexes start at
1. The first item is at index 1, the second at index 2, and so on. Many other programming languages start at 0 — Scratch does not. Watch out when you read code online.
Where to find lists in Scratch
Open the orange-yellow Variables palette. (Yes — lists live with variables, because Scratch sees them as a fancier kind of variable.) Near the top you'll see two big buttons:
- Make a Variable — the one you've been using.
- Make a List — the new one. Click this.
A small dialog asks for the list's name and whether it should be for all sprites or only for this sprite. Pick a clear name (like shopping), leave "For all sprites" ticked, and click OK.
A new section appears at the bottom of the Variables palette with eight or so block-shaped tools — add [thing] to [shopping v], item (1) of [shopping v], length of [shopping v], and friends. We will not use them today. They are next lesson's job.
The watcher widget
The moment you create a list, an empty box appears on the Stage with your list's name at the top. That's the watcher. It updates live: add an item, watch a new row appear. Remove an item, watch the row vanish and the others renumber themselves.
You can also type directly into the watcher on the Stage to add starter items without writing any code — useful for setting up a list for testing. Click the "+" at the bottom-left of the watcher to add a row.
When to reach for a list instead of a variable
Use a variable when there's only one of something:
- The current score.
- Whether the door is open (yes/no).
- The player's name.
- How many lives are left.
Use a list when there are many of the same kind of thing:
- The names of all enemies.
- Every high score ever achieved.
- The questions in a quiz.
- Every word the player has typed.
- The path of x-positions the cat has walked through.
Worked Example — make a shopping list with no code 12 min
No blocks today. Just clicks. We're getting comfortable with the tool before we touch the code blocks next lesson. This is the very first piece of our Shopping List Helper.
Step 1 — Open a new Scratch project
Brand new project. Default cat. We don't need the cat for anything today — it's just along for the ride.
Step 2 — Open the Variables palette
Click the Variables palette (orange-yellow circle on the left). You should see two buttons at the top: "Make a Variable" and "Make a List".
Step 3 — Click "Make a List"
A dialog appears. Type the name shopping. Leave "For all sprites" ticked (default). Click OK.
Step 4 — Find the watcher on the Stage
Look at the Stage. There's now an empty rectangle in the top-left labelled shopping. Underneath it says length 0. That's your list's watcher. The list exists; it just has nothing in it.
Step 5 — Add items directly on the Stage
At the bottom-left corner of the watcher, click the small + button. A text box appears inside the watcher with row number 1. Type Roti. Press Enter. Click + again, type Telur. Press Enter. Keep going until you have:
- Roti
- Telur
- Bawang merah
- Cili
- Ais krim
The watcher should now say length 5.
Step 6 — Delete an item with the X
Hover over the row that says Cili. A small × appears on the right. Click it. The row vanishes. Ais krim is now item 4, and length is now 4. Items below a deleted row slide up to fill the gap.
Step 7 — Edit an item by clicking it
Click directly on the text Bawang merah. It becomes editable. Change it to Bawang putih. Press Enter. The change saves. The index stays the same (still item 3) — you only changed what's in the box, not the box's number.
Step 8 — Resize and hide the watcher
Drag the bottom-right corner of the watcher to make it bigger or smaller. Right-click (or two-finger click) on the watcher → "hide". The list still exists in the Variables palette — only the on-Stage display is hidden. Untick the box next to shopping in the Variables palette to do the same with a click.
The full result
shopping 1 Roti 2 Telur 3 Bawang putih 4 Ais krim length 4
Four items, edited, numbered, ready. Zero blocks placed. This is the seed of our Shopping List Helper.
What you just did: created a real, working list and learned its three visible parts — the name, the numbered items, the length. Next lesson you'll add items, read items, and ask the length from code. Today you just need to see a list and know what it looks like.
Try It Yourself — three exercises 15 min
Goal: In the same project, make a second list called kawan ("friends" in Malay). Add at least five names of your classmates by typing into the watcher. Don't add any blocks. Take a moment to read out loud: "Item 1 of kawan is ___, item 2 of kawan is ___…" all the way through. This will train your brain to think in indexes.
Think: If you delete item 2, does item 5 stay item 5? Try it. (Spoiler: it becomes item 4, because everything slides up.)
Goal: Decide: list or variable? For each of the following pieces of information, write down (in a notebook or a chat to yourself) whether you'd store it as a variable or a list, and why.
- The current level number in your platformer (e.g. "Level 3").
- Every word the player has guessed in a word game.
- Whether music is muted (on or off).
- The names of all the enemies still alive on the Stage.
- The current high score.
- The last 10 mouse-x positions, so the cat leaves a trail.
Think: Rule of thumb — "one of these" = variable, "many of these" = list. Re-read your six answers and check they match the rule.
Reveal the answers
- Variable — one level at a time.
- List — many guesses, growing.
- Variable — one yes/no.
- List — many enemies, possibly many names.
- Variable — one score (the top one).
- List — many positions, growing as the cat moves.
Goal: Create a third list called quiz-answers and add exactly these five items in order: blue, red, green, yellow, purple. Now without deleting and retyping, change the order so it reads red, blue, green, yellow, purple. (Hint: edit the item text directly — you don't need to add or remove rows, just change what's in the first two.)
Think: Lists don't have a "swap" tool in the watcher. The next few lessons will teach the code blocks for inserting, replacing, and deleting from any position — and by Lesson 13 you'll write a real bubble sort that swaps items for you. Today you've felt the limit of click-only editing — the code makes it powerful.
Mini-Challenge — Aisya's overflowing variable 5 min
"Where did my high score go?"
Aisya is building a memory game. She wants to keep every player's name on a leaderboard. She writes this:
ask [What is your name?] and wait
set [leaderboard v] to (answer)
ask [Next player, what is your name?] and wait
set [leaderboard v] to (answer)
ask [Next player, what is your name?] and wait
set [leaderboard v] to (answer)
After three players have entered their names, she looks at the leaderboard watcher and only sees the last name. The first two are gone forever. Why?
Reveal the fix
leaderboard is a variable, not a list. A variable holds one value at a time. Each set [leaderboard v] to (answer) wipes whatever was there and writes the new answer on top. The first two names are gone — the variable can't hold them.
The fix is to make leaderboard a list instead. Delete the variable, click Make a List, name it leaderboard. Next lesson you'll learn the add (answer) to [leaderboard v] block — which appends instead of overwrites. For now, the lesson is: variables overwrite; lists grow. Pick the right tool for the job.
Recap 3 min
You met a brand-new kind of container. A variable is a single box with a name; it holds one value, and setting it again wipes whatever was there. A list is a row of numbered boxes that all share one name; each box holds an item, and each box has an index starting at 1. Lists live in the Variables palette behind the Make a List button. The on-Stage watcher widget shows the name, the numbered items, and the length — and it updates live, which makes it the best debugger you'll have in the next seven lessons.
- List
- A named container that holds many values in a fixed order. Created with the Make a List button in the Variables palette.
- Item
- One value inside a list. Items can be numbers, words, or sentences. The watcher shows each item on its own row.
- Index
- The position number of an item in a list. In Scratch, indexes start at 1 — never 0. The first item is at index 1, the second at index 2.
- Length
- How many items the list currently holds. An empty list has length 0. The watcher shows the length at the bottom.
- Watcher
- The small Stage widget that displays a variable's value or a list's items. Tick or untick its box in the Variables palette to show or hide it.
Homework 2 min
The Three-List Survey. No code blocks. All clicks. You're getting fluent with lists as things before you start coding them.
- Open a new Scratch project. Save it as
HW-L3-06-Three-Lists.sb3. - Make three lists:
makanan-kegemaran("favourite foods"),warna("colours"), andkawan-sekelas("classmates"). - Using only the + button on each watcher, fill each list with at least 5 items. Real items — what you actually like, real colours, real classmate names.
- Right-click each watcher → choose "large" view → re-arrange the three watchers on the Stage so they don't overlap.
- For each list, write down on paper: what is item 1, what is item 3, what is the length?
Bring back next class:
- The
.sb3file. - Your three "item 1 / item 3 / length" answers on paper.
- Your answer to: "If you delete item 2 from
warna, what happens to the index of the item that used to be at position 5?"
Heads up for next class: SCR-L03-07 · Creating Your First List brings out the code blocks. You'll meet add [thing] to [list v], delete (1) of [list v], and delete all of [list v] — the three ways to grow and clear a list from a script, and the start of automating our Shopping List Helper.