Scratch
Beginner
40 mins
Teacher/Student led
+170 XP
Pupils work on their own device

Code a Game That Uses Your Model

Students load their trained Teachable Machine image model into Scratch and build a rock–paper–scissors game against the computer, then tune the confidence threshold and test what happens when it is set too low or too high.

Teacher Class Feed

Load previous activity

    1 - Start: What We're Building ~4 mins

    Illustration for Start: what we're buildingYou can already train an image model for hand gestures. Today in Scratch you will load that model into a rock, paper, scissors game and play against the computer.

    Before you build, think: what might go wrong if the model is only slightly sure about a gesture? Have your model's link ready: you will start a new project and build the game step by step, testing it as you go.

    2 - The Plan: Four Parts to Build ~2 mins

    Your rock, paper, scissors game has four parts:

    1. Load your model into Scratch so the project can use it.
    2. Read what it sees from the webcam, and only act when it is confident enough.
    3. Pick the computer's choice at random.
    4. Compare the two and decide win, lose or draw.

    The confidence threshold is the interesting one: it decides how sure the model has to be before your game acts on what it thinks it sees.


    3 - Set Up Stretch3 and TM2Scratch ~3 mins

    Set up a new project in Stretch3 with the TM2Scratch extension:

    1. Go to https://stretch3.github.io/ and start a new project.
    2. Delete the Cat sprite.
    3. Click the Extensions button at the bottom left of the screen and choose TM2Scratch (not TMPose2Scratch or Posenet2Scratch). This extension lets you use Google Teachable Machine image models in Scratch.
    4. The extension tries to use your computer's camera straight away. If your browser asks, click Allow. You should now see what the camera shows on the stage.


    4 - Add a Sprite ~2 mins

    Add a new sprite to the project that will represent the computer's choice in the game. You can choose any sprite you like, but for this example, we'll use the 'Gobo' sprite.


    123learn · Online learning platform

    Unlock the full learning experience

    You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2026. Unauthorised use, copying or distribution is not allowed.

    Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more