how to make a locker in scratch

Create a Locker in Scratch: Step-by-Step Guide

By Amanda Rodriguez
AD

Welcome to the world of creative coding! In this step-by-step guide, we'll show you how to create a functional locker system in Scratch, a popular online platform for coding and game creation. This project will not only help you learn Scratch programming but also develop your problem-solving skills. So, let's dive in!

Before we start, ensure you have a Scratch account. If you're new, sign up at scratch.mit.edu and familiarize yourself with the interface. We'll be using blocks of code to create our locker, so don't worry about typing out complex commands!

designing the locker

The first step in creating our locker is to understand what we want it to do. Here's a simple plan:

AD
How to make a Locker/Safe with Combination Number Lock from cardboard
How to make a Locker/Safe with Combination Number Lock from cardboard
♻️ DIY: Haz tu propio CASILLERO/LOCKER organizador de materiales - ESPECIAL DE REGRESO A CLASES
♻️ DIY: Haz tu propio CASILLERO/LOCKER organizador de materiales - ESPECIAL DE REGRESO A CLASES
Diy cute mini locker **CAN ACTUALLY LOCK**
Diy cute mini locker **CAN ACTUALLY LOCK**
  • We'll create two sprites, one for the locker and one for a padlock.
  • The locker will start closed, and the padlock will be over it.
  • Clicking the green flag will start the game. When you click the locker, it will open, and the padlock will move away.
  • Clicking the locker again will close it, and the padlock will return.

Now, let's turn this design into reality.

Creating the Sprites

First, let's create our sprites. Click on the 'Choose a Sprite' button and select 'Make a Sprite'. Here's what to do:

diy_Locker•☆•
diy_Locker•☆•
How to Make a DIY Locker from Cardboard
How to Make a DIY Locker from Cardboard
DIY mini locker #short #craft #craftideas #handmade #diy
DIY mini locker #short #craft #craftideas #handmade #diy
  1. Draw a simple rectangle for the locker and a small circle for the padlock. Give them suitable costumes (colors).
  2. Change the locker's starting position to -140 (x) and -60 (y), and the padlock's to -160 (x) and -80 (y).

Your lobby should now look like a closed locker with a padlock over it.

Scripting the Locker

Next, let's add code to our locker sprite. Click on it, then click on 'Events' > 'When green flag clicked'. Add these blocks:

AD
  1. Set 'Locker v' to 0 (this will control the locker's state - 0 for closed, 1 for open).
  2. Show the padlock.

The locker should now start closed with the padlock over it when you click the green flag.

a purple mini locker sitting on top of a counter next to a vase filled with flowers
a purple mini locker sitting on top of a counter next to a vase filled with flowers
✨ DIY Aesthetic Locker Makeover Red theme 🍓 | Handmade decor | Cozy Pinterest vibes
✨ DIY Aesthetic Locker Makeover Red theme 🍓 | Handmade decor | Cozy Pinterest vibes
DIY - Cinnamoroll Mini Locker Organizer #shorts #sanrio
DIY - Cinnamoroll Mini Locker Organizer #shorts #sanrio
Learn to Draw a Locker
Learn to Draw a Locker
🌹 DIY Locker Organizer | How to make Mini Locker #Miniaturelocker #lockerorganizerdiy1
🌹 DIY Locker Organizer | How to make Mini Locker #Miniaturelocker #lockerorganizerdiy1
the instructions for how to open a locker with an alarm clock on it and arrows pointing in
the instructions for how to open a locker with an alarm clock on it and arrows pointing in

Now, let's add clicking functionality to the locker. Click on 'Events' > 'When this sprite clicked'. Add these blocks:

  1. If 'Locker v' is 0, change 'Locker v' to 1 and hide the padlock. Otherwise, change 'Locker v' to 0 and show the padlock.
  2. Change the locker's costume based on 'Locker v'.

Your locker should now open when clicked and close when clicked again, moving the padlock in sync.

AD

Adding a locker combination

Let's make our locker more interesting by adding a combination. Here's our new plan:

How to Make a Safe Locker with Smart Key
How to Make a Safe Locker with Smart Key
  • We'll add numbers 1-3 to our locker sprite. Clicking these numbers will change the combination input.
  • The correct combination will be 123. If the user guesses it, the locker will open.

Sounds fun? Let's code it!

Adding Numbers to the Locker

Change your locker's costume to include numbers 1, 2, and 3. Make them look like buttons. Then, add these scripts:

AD
  1. Under 'Events' > 'When this sprite clicked', add blocks to change 'Number v' (a variable to keep track of the combination attempt) based on which number is clicked:
    • For 1, change 'Number v' to 1 * 100 + (Number v mod 10 + 1)
    • For 2, change 'Number v' to 1 * 100 + (Number v mod 10 + 2)
    • For 3, change 'Number v' to 1 * 100 + (Number v mod 10 + 3)

Now, clicking the numbers will change the combination attempt.

Implementing the Combination Mechanism

Add these blocks to 'When green flag clicked' script:

  1. Set 'Number v' (our combination attempt variable) to 0.
  2. Repeat 'forever':
    • If 'Number v' equals 123, broadcast 'Open Locker' and stop the script.

Now, when the correct combination is entered, the locker will open.

Finally, add these blocks to the locker's 'When I receive Open Locker' event:

  1. Set 'Locker v' to 1 (to open the locker).
  2. Hide the padlock.

And that's it! You've created a functional locker with a combination in Scratch. Now, go ahead and show it off to your friends or create more complex projects.

Happy coding! Remember, the key to mastering Scratch (and any other skill) is practice. Keep creating and exploring!

AD