Scratch Silver III
Scratch Silver II
SCRATCH SILVER I
SCRATCH GOLD III
1 of 3

4.03 Items for sale

Your shop needs items for sale. Each item will have a price that will be added to a total variable.

You will need to keep track of how much your customer is spending.

Add a new variable called total for all sprites.

Click on your seller sprite and add a script to set the total to 0 when the project starts.

Click on Variables in the Code tab, then click on Make a Variable.

Variable blocks

Type in the name of your variable. You can choose whether you would like your variable to be available to all sprites, or to only this sprite. Press OK.

Create variable

The variable will show on the Stage:

Variable on the stage

If you want to hide the variable on the Stage, uncheck the box next to the variable in the Variables blocks menu.

Setting a start value

If your variable should have the same starting value every time your project is run, then add a script to set it:

What items will your customer(s) be buying?

  • Some kind of food or drink
  • Sports equipment, toys, or gadgets
  • Magic wands, potions, or spell books
  • Clothing or other fashion items
  • Your idea

Add a sprite for the first item you’re going to sell in your shop.

If you like, you can add a price to the costume using the text tool in the Paint editor. Or add a price to the backdrop and position the item next to it.

Examples of items with amounts written next to them.

Add a script to change the total by the price of your item when the customer clicks on the sprite.

It’s also a good idea to play a sound to give the customer feedback that they have added an item.

The add a sound icon

Select the sprite that you want to have the new sound, then select the Sounds tab. Each sprite starts with a default sound:

The Sounds tab open in the Scratch editor.

Scratch has a library of sounds that you can add to your sprites. Click on the Choose a Sound icon to open the Sound Library:

The 'Choose a Sound' icon highlighted.

To play a sound, hold your mouse cursor (or your finger, if you are using a tablet) over the Play icon:

'Play' icons.

Click on any sound to add it to your sprite. You will be taken straight back to the Sounds tab and you will be able to see the sound that you have just added:

A newly inserted sound in the Sounds tab.

If you switch to the Code tab and look at the Sound blocks menu, you will be able to select the new sound:

The 'Sound' blocks menu, with the new sound available for use within blocks.

Tip: You can also add sounds to the Stage.

Test: Click on your item and check that the value of the total variable increases by the price of the item, and you hear the sound effect. Click more times to see the total go up.

Click the green flag to start your project and make sure that the total starts at 0.

Add more items to your shop.

You can either:

  • Duplicate the first item and then add a new costume in the Paint editor
  • Add a sprite and then drag the when flag clicked script from the first item to your new item

Add a price label to the costume or backdrop if you are using them.

Click on your new Item sprite in the Sprite list then click on the Code tab.

Change the amount the total changes by to the price of your new item.

Test: Click the green flag to start your project and click on items to add them. Check that the total increases by the correct amount each time you click on an item.

If you have added price labels, make sure they match the amount that gets added to the total, or your customers will be confused!

Debug: You might find some bugs in your project that you need to fix. Here are some common bugs.

Check that you have set the start value of the total variable in the when flag clicked script on your seller sprite.

Check that each item has a when this sprite clicked script that changes the total by the correct amount for that item — you might have changed the price for the wrong sprite.

Check that you have used the change block and not the set block to change the total. You need to use change to add the price to the total, you don’t want to set the total to the price of the item that was just added.

×
×

Cart