Scratch
Beginner
40 mins
Teacher/Student led
+150 XP

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

    A student makes the scissors sign with two fingers at a computer running ScratchToday you will load your hand gesture model into a rock, paper, scissors game in Scratch, and play against the computer.

    Think first

    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 - Set Up Stretch3 and TM2Scratch ~5 mins

    We will build the game in Stretch3, a free version of Scratch that has the extension we need.

    1. Go to stretch3.github.io. A new Scratch project opens.
    2. Delete the cat sprite: click it in the sprite list, then click the small bin icon on its corner.
    3. Click the Extensions button in the bottom left corner of the screen and choose TM2Scratch (not TMPose2Scratch or Posenet2Scratch).
    What TM2Scratch does

    It lets your Scratch project use a Google Teachable Machine image model.

    Camera

    The extension turns your camera on straight away. If the browser asks, click Allow. You should then see what the camera shows on the stage.

    No camera, or the camera is blocked?

    You can still build and play this game. Follow every step, and watch a neighbour's screen when a step needs a camera. When you reach Get Player Choice, add the three key scripts as well, so the keys 1, 2 and 3 stand in for your hand.



    3 - 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.


    4 - Create Variables ~2 mins

    Create two new variables:

    • playerChoice - to store the player's choice.
    • computerChoice - to store the computer's choice.

    Leave the tick box beside each new variable ticked, so both show on the stage while you play. That is how you will see what the computer picked: 1 is rock, 2 is paper and 3 is scissors.

    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