Scratch
Beginner
40 mins
Teacher/Student led
+55 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 - Setup Scratch 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.
    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.



    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.

    5 - Randomize Computer Choice ~2 mins

    In this step, you will add code to your sprite to randomly set the computer's choice to 1, 2, or 3. These numbers will represent the computer's choice of rock, paper, or scissors, respectively:

    • 1 = Rock
    • 2 = Paper
    • 3 = Scissors

    Add the following code to your sprite:

    when green flag clicked set [computerChoice v] to (pick random (1) to (3))
    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