Skip to main content

Stage 5: Show the AI Prediction

Course progressStage 5 of 10
~90 min
Your two tools

Keep both tabs open all week. Open in a new tab — don’t use the buttons in this page to leave the course.

Build

a sprite that says what the AI sees, live, on the stage

Learn

how a forever loop lets the AI talk to the game many times per second

Ship

a Scratch-style program that updates the screen with every hand sign

Teacher demo

Show the room — three blocks make this stage work:

  1. when green flag clicked (yellow event block).
  2. forever (orange control block).
  3. say with the AI prediction block inside it.

Show the snap. Click the green flag. The sprite says "Rock". Switch hands. The sprite says "Paper". Get the reaction — this is the moment of the week for many campers.

The big idea

Until now, your AI has only talked to the Preview panel in Teachable Machine. Today the AI talks to the game. The cat sprite is going to say "Rock", "Paper", "Scissors", or "Nothing" — live, every moment, depending on what your hand is doing.

Three blocks make this happen:

when 🟢 clicked


forever

▼ (every single moment, over and over)
say (what the AI sees right now)

The forever block is the heartbeat. It runs the inside code over and over — many times per second. Inside the forever, we ask the AI "what do you see?" and tell the sprite to say it. The result is a sprite whose mouth moves the moment your hand does.

If you remember from school: a loop is just "do this again." That's all forever is — Scratch's word for do this again, never stop.

New words
sprite
the character on stage (the cat, for now)
event block
a block that starts when something happens (like clicking the flag)
forever
a loop block that repeats forever
say
a Scratch block that makes a sprite say something in a speech bubble
Before you start

Your RAISE Playground project from Stage 4 should be open. The AI extension should be loaded with your model URL.

Build it

Step 1 — Find the green flag event

In the block palette, look for the Events category (usually yellow). Drag out the block that says:

when 🟢 clicked

Place it in the script area on the right side. This block doesn't do anything by itself — it just says "start here when someone clicks the green flag."

Step 2 — Add a forever loop

In the block palette, look for Control (usually orange). Drag out:

forever

Snap it directly under the when 🟢 clicked block. The shape will lock in place.

The forever block has a big opening in the middle. Anything you put inside that opening will run again and again.

Step 3 — Make the sprite say what the AI sees

Look for the Looks category (usually purple). Drag out the say block:

say [hello]

Snap it inside the forever block (in the open area).

Now find your AI prediction block — it's the pink or purple block in the AI category that returns the name of whatever the AI sees right now. Drag that AI block into the white text field inside the say block. It should snap in, replacing the word "hello".

Your finished script should look like:

when 🟢 clicked
forever
say (what the AI sees)

Step 4 — Press the green flag and test

Click the green flag at the top of the stage. The cat sprite should start showing a speech bubble.

Hold up a Rock hand sign. The bubble should say Rock. Hold up Paper. The bubble updates to Paper. Move your hand out of frame. The bubble says Nothing.

If the speech bubble updates as your hand changes, you did it. Save the project.

Understand it

The forever loop is the most important pattern in any game you'll ever build. Every video game has one. It runs every fraction of a second, checking everything — what keys you pressed, what the AI sees, what the score is, what enemies are doing — and updating the screen.

In Python Arcade (a different camp course), the kids call it a game loop. In Scratch, it's called forever. Same idea, different name. Many times per second, the same code runs and updates everything.

The reason say uses the AI's prediction inside it is a small but powerful idea: one block can be the input to another block. You're plugging the AI's answer straight into the sprite's mouth. No saving, no waiting. The AI says it, the sprite repeats it.

The reason the green flag matters is that without it, your forever loop wouldn't start. The flag is the power button. Every Scratch project waits for a green flag (or some other event) before doing anything. Otherwise the program just sits there.

You wrote your first real piece of AI-controlled code today. Three blocks, but every game you build from here on is a longer version of these three blocks.

Try this

Learning beat

Try this

Three short experiments. Predict before you run, then test your guess.

Predict first

Take the forever block away (drag it to the trash). Now you have just when 🟢 clicked and say AI-prediction. Predict: what happens if you click the green flag? Does the sprite say anything? For how long?

Compare

Swap say for think (another Looks block). Click the green flag. What's different? Which one fits the vibe of an AI better — speaking out loud, or quietly thinking?

Connect

Stage 6 turns "the sprite says the prediction" into "the sprite moves because of the prediction". Look at the three blocks you used. Which one stays exactly the same in Stage 6? (Hint: it's the loop.)

Test your stage

  • Clicking the green flag starts the program.
  • The sprite shows a speech bubble.
  • The bubble updates live when you change hand signs.
  • Rock, Paper, Scissors, and Nothing all show up (at least 3 of the 4).
  • The project is saved.
  • Design check. Watch your speech bubble for 10 seconds without moving your hand. Does it flicker between two words? Flickering means your model has a weak spot at this exact position — note it, you can fix it in any spare moment.

If it breaks

  • The speech bubble is empty. The AI block isn't snapped into the say block properly. Pick it up and try again — the slot it goes into is the white text field.
  • The bubble says "undefined" or shows weird text. Your model URL didn't load. Open the AI extension area and re-paste the URL. Make sure it ends with /.
  • Nothing happens when I click the green flag. Check that the when 🟢 clicked block is at the top of your script, with nothing above it. Other blocks have to snap underneath it, not on top.
  • The bubble shows "Rock" forever, no matter what I do. The forever loop might be missing — the say block is running once and then stopping. Drag the say block into the forever block's middle slot.
  • The webcam permission popup keeps appearing. Click Allow. Some browsers reset the permission when you switch tabs.
Coach notes

This is the magic moment of camp for most kids 7–9. The first time their hand controls the cat, they will giggle, gasp, or shout. Let it happen. Build 5 minutes of free-play time into this stage on purpose — it's the emotional payoff for two days of training.

The trickiest concept here is the AI block goes inside the say block. Many campers will put both blocks side by side instead. Walk the room as soon as Step 3 starts and watch for that error.

If a kid finishes in 30 minutes, push them straight into the medium stretch (better phrases). The hard stretch — opponent sprite with if/else — is a real introduction to conditional logic; reserve it for fast finishers and pair them up so they can talk through the if/else patterns.

This is also a 90-minute stage. Plan a snack break around the 45-minute mark, ideally right after Step 4 succeeds (the green-flag moment is a natural high to break on).