How to Make Dice
This article will walk through creating a simple die with Scratch. When finished a user should be able to press space and a random dice face should show on the screen. Start by creating a new project and delete the Scratch Cat sprite.
Creating the Costumes
Before coding is begun, several costumes have to be made. For this, 6 costumes are required, each to represent a face of the dice. It does not have to be the traditional style, it could even be just numbers. However, make sure they are all different. Once that is finished, name the costumes from 1-6. This will be necessary later on.
Coding the Dice
Now that all the costumes have been created, it is time to code the dice to add functionality.
Starting the Program
Unlike manyШаблон:Citation needed programs on Scratch, which start with the block, this program will start with the
block. Just to make sure that the dice displays the output in the centre of the stage, use the
block. The code should look like this:
Rolling the Dice
Now that the program can start, it is time to create the main mechanism. The code needs to be added to randomise the outcome. For this, the and
blocks are needed. The random block with pick a random number between 1 and 6, which will make the sprite will switch its costume to the costume named with the number. Now join them together like so:
Now join all the blocks together to form this script:
This tutorial is now complete.