Learning Goals 3 min
By the end of this lesson you will be able to:
- Use item (1) of [shopping v] to read one specific item out of a list by its position number.
- Recite the rule: Scratch list indexes start at 1, not 0 — and explain why typing
0reports an empty value, not the first item. - Use the special dropdown options item (last v) and item (random v) to grab the newest item or a surprise item, and drop the result into a say () for () seconds block.
Warm-Up — counting from one 7 min
Quick question. Aunty Siti's shopping list has these three items, in order:
kangkungtauhucili
What's item number 1 on her list?
Reveal the answer
kangkung. The first item. That feels obvious to a human — and it's also how Scratch does it. Scratch starts counting at 1.
This sounds like a "well, obviously" rule, but it's worth saying out loud because most other programming languages (Python, JavaScript, Java, C++, all the big ones) start counting at 0 — so the first item is item number 0, the second is item 1, and so on. That's called zero-indexed. Scratch is one-indexed: human-friendly, beginner-friendly. When you eventually graduate to a text language, the most common L1-to-Python bug in the whole world is forgetting that the rule changed.
Today's lesson is the block that reads items back out. The block has a number slot in it. That number is the index. And the index — as Aunty Siti reminds us — starts at 1.
New Concept — the item-of block 15 min
You can add items to a list (lesson L03-08). The list watcher shows them all numbered. But how does a script get one specific item back out so you can put it in a say-block, a compare, or a costume change? The answer is one round reporter in the Variables palette.
Where to find it
Open Variables. Scroll down past the add and delete blocks. You'll find:
(item (1) of [shopping v])
Drop it into any round slot — a say-block, a set-variable, a compare. The reporter reports the item at the position you ask for. If the list has kangkung, tauhu, cili and you ask for item 1, it reports kangkung. Ask for item 2, it reports tauhu. Item 3, cili.
The 1-not-0 rule
Try changing the number to 0. What does it report?
when flag clicked
say (item (0) of [shopping v]) for (2) seconds
Same thing if you ask for item 4 when the list only has 3 items, or item -1, or item 500. Out-of-range indexes report an empty value. Scratch doesn't crash, doesn't beep, doesn't even change colour. It just hands you back nothing. That silence is a common source of "why is my cat saying nothing?" bugs.
The (last v) shortcut
You won't always know how long the list is. Maybe the user just typed 7 things, maybe 700. To grab the most recent item without doing maths, click the small number slot — a tiny dropdown arrow appears giving you three options: any number, the special word last, or random. Pick last:
when flag clicked
say (item (last v) of [shopping v]) for (2) seconds
This is the "what did the user most recently add?" shortcut. Combine with the add-to-list pattern from last lesson and you've got an instant confirmation message ("You added: roti").
The (random v) shortcut
Same dropdown, second option. random picks a random item from the list every time the reporter runs.
when flag clicked
forever
say (item (random v) of [shopping v]) for (1) seconds
end
Putting it inside say
The item-of block is a round reporter — it fits into any round slot. The most common place to drop it is the white slot of say () for () seconds. That's how you make the cat speak the contents of the list.
when flag clicked
say (item (1) of [shopping v]) for (2) seconds
say (item (2) of [shopping v]) for (2) seconds
say (item (3) of [shopping v]) for (2) seconds
Worked Example — the random pasar shouter 12 min
Open Scratch. We'll fill a list with three pasar items and make the cat shout a random one every couple of seconds.
pasar watcher top-left; the cat (the ✏️ sprite) reads one item at a time out loud — "item 1 = kangkung" — instead of smushing them together. This per-item reading is what the Find feature builds on later.Step 1 — Start fresh
New project. Default cat. Make a list called pasar, For all sprites.
Step 2 — Drop the hat
From Events: when ⚑ clicked.
Step 3 — Reset and fill the list
From Variables: delete all of [pasar v], then three add [...] to [pasar v] blocks with kangkung, tauhu, and cili typed in. The list watcher fills with three items.
Step 4 — Read item 1 to test
From Looks: say () for (2) seconds. From Variables: drag item (1) of [pasar v] into the round slot. Click the flag. The cat says kangkung for 2 seconds. Good — indexing works.
Step 5 — Try item 2 and item 3
Change the number from 1 to 2. Click the flag. The cat says tauhu. Change to 3. The cat says cili. Each number corresponds to a row.
Step 6 — Try item 0 to see the silence
Change the number to 0. Click the flag. The cat says… nothing. Empty thought bubble for 2 seconds. Same with 4, 5, or -1. Out-of-range = silence. Remember this when your cat goes mute.
Step 7 — Switch to random
Click the small number slot — the dropdown arrow appears. Pick random. The slot now shows (random v).
Step 8 — Wrap in a forever loop
From Control: forever. Drag the say block (with the item-of inside it) into the forever C. Click the flag. The cat shouts a random pasar item every 2 seconds, forever — sometimes the same one twice in a row (that's normal for random).
The full assembled stack
when flag clicked
delete all of [pasar v]
add [kangkung] to [pasar v]
add [tauhu] to [pasar v]
add [cili] to [pasar v]
forever
say (item (random v) of [pasar v]) for (2) seconds
end
What you just built: the foundation of every quiz, fortune-teller, NPC, and "random whatever" project ever made in Scratch. The combo is always the same: a list of options + item (random v) of [list v] + an output block (say, broadcast, switch costume, play sound).
Try It Yourself — three indexing drills 15 min
Goal: Open your homework from L03-08 (the names and foods roster). Add a second script to the cat: when the 1 key is pressed, the cat says item (1) of [names v] for 2 seconds. That should say the first classmate.
when [1 v] key pressed
say (item (1) of [names v]) for (2) seconds
Think: Notice you're reading from a list you didn't fill in this script — the names came from last lesson's homework. Lists are saved with the project, remember? Today's script doesn't care how they got there.
Goal: Make a list called jawapan with three answer options: Ya, Tidak, Mungkin. Build a fortune-teller — when the space key is pressed, the cat says a random item for 2 seconds. Like a Magic 8-Ball in Bahasa.
when flag clicked
delete all of [jawapan v]
add [Ya] to [jawapan v]
add [Tidak] to [jawapan v]
add [Mungkin] to [jawapan v]
when [space v] key pressed
say (item (random v) of [jawapan v]) for (2) seconds
Think: The random reporter re-rolls every single time it runs. Press space ten times and you'll see the answer change (sometimes the same one twice in a row — that's how random actually works, not a bug).
Goal: Build a "last thing I added" confirmer. Use ask-and-wait inside a forever loop to add answers to a list called todo, but right after adding, the cat says Added: and then the last item, using item (last v) of [todo v] and the join operator.
when flag clicked
delete all of [todo v]
forever
ask [What to do?] and wait
add (answer) to [todo v]
say (join [Added: ] (item (last v) of [todo v])) for (1) seconds
end
sapu rumah; the cat replies Added: sapu rumah for 1 second; the box pops up again.Think: You're meeting join () () early — it glues two strings together. last is safer than typing a hard-coded number because the list keeps growing — by the 10th item, item 1 is way out of date but item last is always the newest.
Mini-Challenge — the zero index 5 min
"Raj's silent quiz"
Raj is building a quiz. He has a list called soalan with three questions in it. He wants the cat to ask the first question on the green flag. He writes this:
when flag clicked
say (item (0) of [soalan v]) for (3) seconds
What's wrong, and what should Raj change to make the cat say the first question?
Reveal one valid solution
Raj has a "started programming on the wrong website" bug. He typed 0 for the first item because some other language (probably Python or Scratch's older offline clone) starts indexes at 0. Scratch starts at 1. There is no item 0. Asking for it reports an empty string, which is exactly what the speech bubble shows.
The fix is one character — change the 0 to 1:
when flag clicked
say (item (1) of [soalan v]) for (3) seconds
The cat now says question 1. If Raj wants question 2, change to 2. If he wants the last one no matter how many he adds later, click the dropdown and pick last. One. Not zero. Always. Tattoo it on your forearm.
Recap 3 min
You met the block that reads list items back out. item (1) of [shopping v] reports the item at the position you ask for. Indexes start at 1, not 0 — out-of-range numbers (0, negative, past the end) report an empty value with no error. The small number slot has a hidden dropdown with two superpowers: last always picks the newest item, and random picks a random one every time it runs. Drop the reporter into any round slot — most often the white slot of say () for () seconds — and you've got a list-driven speaker, quiz bot, fortune-teller, or NPC dialogue system. Next lesson we learn how to count how many items are in a list with length of [shopping v].
- Index
- The position number of an item in a list. In Scratch, indexes start at 1. The first item is index 1, the second is 2, and so on. Asking for item 0 reports an empty value.
- item () of
- item (1) of [shopping v] — the round reporter that reads one item out of a list. Drops into any round slot (say, set variable, compare, etc.).
- last
- A special dropdown choice in the number slot of the item-of block. Always points to the newest (highest-index) item, no matter how long the list grows. Safer than hard-coded numbers when the list size keeps changing.
- random
- The other special dropdown choice. Picks a random item from the list each time the reporter runs. Foundation of quiz banks, fortune-tellers, and chatty NPCs.
- Empty value
- What Scratch returns when you ask for an item that doesn't exist (item 0, item -1, item 500 in a 3-item list). The speech bubble shows nothing; no error appears. A common source of silent bugs.
Homework 2 min
The Random Pasar Quiz. Build a one-sprite project that quizzes the player on Bahasa pasar vocabulary.
- Make a list called
soalan. On the green flag, empty it, then add five questions likeWhat is kangkung in English?,What is tauhu in English?,What is ayam in English?,What is ikan in English?,What is bawang in English?. - On a key press (try q), the cat picks item (random v) of [soalan v] and uses it as the prompt inside an ask () and wait — drop the item-of reporter into the question slot.
- After the user answers, the cat says
Terima kasih!for 1 second. (We're not checking the answer yet — that's for L03-12.)
Save as HW-L3-09-Pasar-Quiz.sb3. Press q five times and write down which question popped up each time.
Bring back next class:
- The
.sb3file. - Your list of which question came up each time you pressed q. Did any question repeat? Did any question never show up at all? That's random for you.
Heads up for next class: SCR-L03-10 introduces length of [shopping v] — the block that tells you how many items are in the list right now. Combine it with the item-of block and you can do loops like "say every item in the list, one at a time" — properly, no matter how big the list grows.