The seller sprite needs to:
When they have finished choosing items, the customer will click on the seller sprite to pay.
Tell the customer how much their items will cost.
Add a payment sound to your seller sprite so the customer knows that payment is taking place.
Select the sprite that you want to have the new sound, then select the Sounds tab. Each sprite starts with a default sound:
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:
To play a sound, hold your mouse cursor (or your finger, if you are using a tablet) over the Play icon:
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:
If you switch to the Code tab and look at the Sound
blocks menu, you will be able to select the new sound:
Tip: You can also add sounds to the Stage.
Add the
block to your script.play sound until done
Finish the sale. Set total
back to
after payment, 0
say
goodbye and broadcast
next customer
.
You might want to give the customer the option to cancel their shopping.
Ask
Would you like to pay or cancel?
. Add an If
block for answer
=
pay
and inside it put your existing payment blocks.
Add a second
block for If
and inside it add code to cancel the order.answer
=
cancel
To make sure your customer has items in their basket before paying, you can insert an
block.if...else
If
total
then insert your existing script.>
0
Else
say
a helpful message.
Test: Test your project and make sure:
total
gets set back to 0
after a customer pays or cancels.Debug: You might find some bugs in your project that you need to fix.
Here are some common bugs:
You have quite a lot of sprites in your project. Make sure the when this sprite clicked
script is on your seller sprite.
Tip: If you have added it to the wrong sprite, you can drag the code to the seller sprite, then delete it from the other sprite.
Make sure your
block has the say
variable block, not the word total
total
.
When you join
two pieces together, you need to add a space at the end of your first piece of text or at the beginning of your second piece of text.
These have a space at the end of the first part of the join:
Tip: Compare your code with the code examples. Are there any differences that shouldn’t be there?