How to Make an Inventory in Scratch | Tutorial

Alphabets Sounds Video

share us on:

In this lesson, you learned how to create and manage an inventory system in Scratch, which is essential for tracking items collected by a character in a game. By creating a list named “inventory,” you can add and remove items as your character interacts with them, ensuring that the inventory starts empty at the beginning of the game. Additionally, you explored how to check for specific items and allow characters to use them, enhancing the gameplay experience.
  1. What is the purpose of creating an inventory in a Scratch game?
  2. How do you add an item to your inventory when your character collects it?
  3. What happens to an item in the inventory after Giga eats it?

How to Make an Inventory in Scratch

Hey there! Today, we’re going to learn how to make an inventory in Scratch. This is super helpful if you have a game where your character collects items, and you want to keep track of them. By the end of this guide, you’ll know how to do just that. Let’s jump in!

Getting Started

First, let’s talk about the basics. Imagine you have a character in your game that can move around using the arrow keys. There’s also an item, like a star, that appears randomly on the screen. When your character touches the star, it makes a sound and disappears. Cool, right?

Creating an Inventory List

Now, let’s create a list to keep track of all the items your character collects. In Scratch, you can make a list by clicking on the “Variables” category and then selecting “Make a list.” Let’s name this list “inventory.” Once you create it, you’ll see new blocks that let you add or remove items from the list.

Adding Items to the Inventory

To add an item to the inventory, use the block that says “Add thing to inventory.” For example, if you want to add a star, you would use “add star to inventory.” When your character collects the star, it gets added to the list.

Removing Items from the Inventory

You can also remove items from the list. Use the block that says “delete item number of inventory” to remove an item at a specific position. For instance, “delete 2 of inventory” will remove the second item.

Starting with an Empty Inventory

Every time you start the game, you might want the inventory to be empty. Use the block “delete all of inventory” at the beginning of your game to clear everything out.

Using Items from the Inventory

Let’s add another item to collect, like an apple. Make it a bit smaller, around 60%. Also, add a character named Giga who wants an apple. Make Giga smaller too, around 70%.

Make the apple collectible just like the star. When your character collects the apple, it gets added to the inventory. Now, when you click on Giga, Giga will say, “I want to eat an apple.”

Checking for Items

To see if the player has an apple, use a block that checks if the inventory contains “apple.” If it does, Giga can say “yum” and eat the apple.

Giving Items to Characters

After Giga eats the apple, you should remove it from the inventory. Use the block that deletes the item number of the apple. This way, the apple disappears from the inventory after Giga eats it.

Conclusion

And that’s how you can create and manage an inventory in Scratch! Now you can add inventories to your own games and make them even more fun. Happy scratching!

  • Have you ever played a game where you had to collect items? What kind of items did you collect, and what did you do with them?
  • If you could create your own game, what items would you want your character to collect, and why?
  • Think about a time when you had to keep track of something important, like toys or books. How did you remember what you had, and how is that similar to using an inventory in a game?
  1. Create Your Own Inventory Game: Use Scratch to create a simple game where your character collects different items, like stars and apples. Try adding new items to your game and see how they appear in your inventory list. Experiment with different sounds and effects when items are collected. Share your game with a friend and see if they can collect all the items!

  2. Inventory Scavenger Hunt: At home or in the classroom, create a real-life scavenger hunt. Make a list of items to find, like a pencil, a book, or a toy. As you find each item, add it to your “inventory” by writing it down on a piece of paper. Discuss how this is similar to adding items to an inventory in Scratch. What happens when you find all the items?

  3. Story Time with Inventory: Imagine a story where your character needs to collect items to solve a problem. Write a short story or draw a comic strip showing how your character uses their inventory to help others, like giving an apple to Giga. Think about what other items your character might need and how they could use them. Share your story with the class!

Sure! Here’s a sanitized version of the YouTube transcript:

Hi everyone, it’s Zia here. Today I wanted to show you how to make an inventory in Scratch. If you have a game or a project where a character can collect items, you might want a way to keep track of those items. By the end of this tutorial, you will be able to do that. Let’s get started.

For this project, I started out with the code from my video on how to make collectible items in Scratch. I recommend watching that video because it explains how all of this code works. The basic idea is that we have a main character who can move around with the arrow keys, and we have an item that, when the green flag is clicked, goes to a random position and waits until the main character runs into it. Then it plays a sound and disappears.

Now let me show you how to make an inventory. We can create a list that will track all of the objects our character has collected. To make a list in Scratch, click on the variables category and scroll down to where it says “Make a list.” We can call this list “inventory” and create it. Now we have a list, and new blocks appear that allow us to add or remove things from this list.

You can add something to the list with the block that says “Add thing to inventory.” This will add whatever you have in that block to the inventory. For example, we could say “add star to inventory,” and that adds it. You can also remove things from the list. With the block that says “delete item number of inventory,” you can delete something at a certain position in the inventory.

If I say “delete 2 of inventory,” it deletes the second item, which is the star. Similarly, if I type in “1,” it deletes the first item in the inventory. If we take the block “add star to inventory” and place it where the star gets collected, we can test that out. The character runs into the star, collects it, and it goes into the inventory.

When I restart the game and collect the star again, it adds it to the inventory again. However, there’s a block called “delete all of inventory.” Let’s make it delete all of the inventory when the game starts, so every time we start the game, our inventory starts out empty.

Now let me show you how to use an item from your inventory. To do that, let’s add another item to collect. This time, I’ll add an apple and make it a bit smaller, around 60%. I’ll also add a character that will ask the player for an apple. Let’s call this character Giga and make Giga smaller, around 70%.

Now we can make the apple collectible in the same way as the star. We can take the code that allows the star to be collected and drag it to the apple. We can then change it to add “apple” to the inventory instead of “star.”

Let’s test that out. I walk over to the apple, pick it up, and click on Giga. Giga says, “I want to eat an apple.” If the player has an apple in their inventory, we want to give that apple to Giga, which means removing it from the player’s inventory.

To check if the player has an apple, go to the variables category and scroll down to the list blocks. There’s a block that checks if the inventory contains a certain item. If I type in “apple,” it will say true if the inventory contains an apple. If we had deleted all of the inventory, it would say false.

We can use an “if” block to perform an action only if the condition is true. This next piece of code will only happen if the inventory has an apple. If the inventory has an apple, we want to give that apple to Giga. First, we can make Giga say something like “yum.”

Let’s test if that’s working. I walk over to the apple, pick it up, and click on Giga. Giga says, “I want to eat an apple. Yum.” Now, I still have the apple in my inventory, but we should remove it since I’ve just given it to Giga.

To delete something from the inventory, we can use the block that deletes a certain numbered item. The apple is currently at position one in the inventory. If I put that block there, when I click on Giga, it will remove the apple from the inventory.

However, if the star is item one in my inventory, Giga will delete item one, which is the star, instead of the apple. We want to delete whatever number the apple is at. To figure that out, we can use the block that gives the item number of a thing in the inventory.

This block will tell us the position of the apple in the inventory. We can place this in the delete block, so it will always delete the item number of the apple in the inventory.

Now, when Giga says, “I want to eat an apple,” it will delete the apple. That’s how you can remove something from the inventory and give it to another character.

Anyway, that’s what I wanted to show you today. I hope you have fun adding inventories to your games. The starter code will be in the description below, so you can remix that. I’ll see you next time, and happy scratching!

This version maintains the instructional content while removing any informal language or unnecessary details.

All Video Lessons

Login your account

Please login your account to get started.

Don't have an account?

Register your account

Please sign up your account to get started.

Already have an account?