A guide to help you understand the basics of Scratch and how to get started with sequential block coding.
What is scratch?
Take a look here: https://scratch.mit.edu/projects/editor/?tutorial=getStarted
Scratch is a block-based visual programming language and online community targeted primarily at children. In computing, a visual programming language is a language that lets users create programmes with visual expressions and symbols rather than text. It’s like making a jigsaw puzzle out of a string of commands.
You can programme your own interactive stories, games and animations and then share these with the online community. Scratch also helps young people learn to think creatively, reason systemically and work collaboratively, which are increasingly becoming essential skills for the 21st century.
Who can use scratch?
Scratch is suitable for mixed ability classes and does not require any prior knowledge of programming. It is designed especially for ages 8 to 16, but can be used by people of all ages. Scratch has been designed so children can learn through exploring, experimenting and tinkering. This allows children to learn independently, freeing up parent or teacher time so they can get on with other tasks or work with another child.
Scratch has its own vocabulary which takes practice to get used to. Below are some common words that you will see when using Scratch:
User interface: the area in which the user communicates with Scratch
Stage area: features the results of your coding. This is the area where you can see your project come alive
Sprites: these are the images that appear on the computer programme screen
Backdrop: is an image that can be shown on the stage
Scripts: are collections of blocks that all interlock with each other. Each block will determine how sprites interact with each other and the backdrop.
Costume: is one of the many different appearances of a sprite. These can be named, created, and deleted. Every Sprite must have a costume.
Coding area: we highlighted this with a red box in this image. This is the place where you can assemble your code by dragging the blocks on the left into this area.
Blocks palette: this is an area of the Scratch User Interface that is located to the left of the Code Area. The block to choose from change depending on which circle you select on the left e.g. ‘Motion’, ‘Looks’, ‘Sound’ or ‘Events’.
Command blocks: these are the different instructions you can give to your Sprites. They are broken down into eight varieties of blocks as shown in the image:
Offline editing: https://scratch.mit.edu/download This is a version of Scratch that can be downloaded and installed on a computer so can be used without the use of the internet
Using Blocks in Scratch
In the image below, you can see that some sprites have been created, but there have been no scripts assigned to them yet – meaning your sprites are just an image at the moment.
To start creating a script, click on the asset you want to apply it to, and then drag the relevant blocks onto the stage area. To add multiple blocks to a script, drag new blocks into the coding area and attach them to your other blocks in the script. You can add new blocks above or below existing blocks and they connect like jigsaw pieces. You can also break them apart by clicking on a block and dragging it to an empty space in the coding area.
Motion blocks can create the following types of movements:
- Moving sprites
- Turning sprites
- Making sprites point in a given direction
- Making sprites move to a given point on the stage, to another sprite or to the mouse pointer
- Changing the x and y co-ordinates of the sprite on the stage
- Making the sprite bounce if its hits the edge of the stage
- Altering the style with which a sprite rotates
These blocks form the basis for a lot of games and animations, below is a screenshot of how using motion blocks may work:
Using the different blocks, my sprite (donut) will:
- Move 10 steps
- Turn 15 degrees
- Glide to a random position on the stage
- And will bounce if it hits the edge of the stage
Every time we click on that block sequence, the donut will repeat the four steps above.
Looks can be used with sprites or backdrops. This type of block allows you to do the following:
- Display text, either for a fixed period of time or indefinitely
- Show or hide your sprites
- Switch costumes for sprites or backdrops for your stages
- Change colour effects or remove them
- Change the size of the sprites
- Move sprites backwards or forwards using layers
Using the different blocks, my sprite (donut) will:
- Say Hello! For 10 seconds
- Switch costume to Abby-b (which I set previously)
- And reduce in size by 50%
Every time we click on that block sequence, the sprite will repeat the three look steps above. If we then click on the motion block, it will take the Abby-b sprite and repeat the four steps from the above example.
These blocks allow you to do the following:
- Play or stop sounds – these can either come from the Scratch library or ones that you have uploaded yourself
- Play drum sounds and notes
- Change or set the volume or tempo
Using the different blocks, my sprite will:
- Make a sound that sounds like a Bite
- The pitch is set to 100
- And the volume set to 90%
Every time we click on the purple blocks – the sound will repeat.
Event blocks are fundamental to Scratch as this tells the script to run. Event blocks allow you to do the following:
- Start everything off
- Blocks for other user interactions
- Trigger events by the backdrop or costume changing
- Broadcast messages from one sprite and then have another sprite respond to that message with an events block
Using the events block, the
- First motion block will be triggered once the green flag is clicked
- If I click on the sprite it will make a chomping sound
These let you control the blocks within your scripts – inserting conditionals, loops, repeats and pauses – making your code much more efficient.
Command blocks allow you to:
- Pause the script
- Add conditionals – wrap these around a set of blocks to make something happen if a condition is met
- Add loops – repeat a set of blocks a given number of times, forever, or until a condition is met
- Stop all loops
- Create and use clones
The two command blocks at the bottom will ensure that after the script has ended, it will wait for 1 second and then repeat the process.
These let you identify what is happening at a given point and make your sprites or background respond accordingly.
These blocks allow you to:
- Detect whether items are touching each other or at a given distance from each other
- Ask the user a question
- Detect key presses and mouse clicks
- Time the runtime of a project
For example, you can use control blocks in games to make the player lose when one object touches another, or to detect if a sprite is moving fast enough to crash through another sprite.
On this example, we have added in the sensing block that means every time the backdrop is switched to ‘backdrop1’, ‘Donut’ sprite will say ‘What’s your name’.
These blocks allow you to:
- Add, subtract, multiply and divide one value by another
- Pick a random number between two numbers you define
- Identify if two values are less than, great than or equal to each other
- Join other blocks together or work with just one part of a block’s value
- Round values and identify whether the result of a calculation has a remainder
When the green flag is clicked, this code will forever check if the value in the age variable is great than the value of 65. If the value is greater than 65, the sprite will say “You can retire” – otherwise, nothing will happen.
Variables are like containers that can hold a number or a word. These blocks will allow you to set your own variable to a value that you give it. For instance, you can create a variable called ‘greetings’ and when you use this within your script you can add a value to it, such as ‘If greetings = 2’ ‘then the script will say hello for 2 seconds’. On your stage, whenever the stage monitor equals 2 your script will respond to the value you set the variable at. A stage monitor is the name of the orange counter which appears on the top left of the stage when you make a variable. The name on this orange counter matches the name you gave when you made a variable block. The counter will change when you set up rules that will change the number in your code e.g. pick a random number.
To give an example, we are going to make a programme that generates two random numbers. The sprite will then report what these two randomly generated numbers are.
First, we want to create two variables to store these two randomly generated numbers. You do this by clicking on Make a Variable and then name them accordingly:
Next, we must set the value of these variables to be random numbers every time the flag button is clicked:
As you can see, we used an Events Block to ensure the script runs, and then used two Operations Block within the Variables Block to set the random number. You can see the two random numbers displayed on the Stage Area in the top left corner.
Next, we need the sprite to tell us what these two numbers are – we do this by using the following Sound Block:
As you can see, this has been made by using the Event, Variables, Operators and Sound Blocks.
“My blocks” Blocks
The primary purpose of these blocks is to make programming easier. They also give you functionality that isn’t built into the other Scratch blocks. For example, you could create a block that would choose at random, hello from a number of different languages.
The above script was created and then, using the My Blocks tab, was saved under a new block. This means you don’t have to re-do the sequence every time you want to use it – allowing you to create more complex and efficient scripts.
Where to start
By signing up to Scratch you are able to save your videos and share them with others in the community. Using the ‘Explore’ tab you can see what other parents and children are creating and the different ways in which Scratch can be used.
As we would encourage children to get stuck straight in, we encourage parents to do the same. Scratch has been designed so that the best way to understand the programme is by exploring the User Interface and developing as many Scripts as possible.
Visit the Scratch webpage here: https://scratch.mit.edu/. Once on the Scratch webpage, the two tabs to begin your exploration are the ‘Create’ and ‘Ideas’ tabs, located at the top of the screen. The ‘Create’ tab will bring up your User Interface and you will be able to see the different command blocks on the left-hand side of the screen, clicking on each block will allow you to begin to assemble your Scripts to move your Sprite.
You can change the look of your Sprite using the Costumes tab and you can amend and tailor sounds using the Sounds tab. Once you have created your Sprite and added in different Scripts, you can save the clip onto your computer. Congratulations, you have made your first online programme!
Scratch in Practice is the area with Scratch where users and the Scratch Team can share ideas, lesson plans and materials from around the world. It is full of resources to help you get started with Scratch, to plan your own lessons and to share ideas across different subjects to enhance curriculum connections.
Using the hashtag #ScratchInPractice, following @RoboticalLtd on Twitter, and making good us of the ‘ideas’ and ‘explore’ area in Scratch will give you plenty of new ideas as well as inspiration for more advanced projects like programming real robots through Scratch!
You can also sign up to the Scratch in Practice mailing list to receive regular updates from the online community!
Now that you have learned a bit about Scratch, we can move on to actually building something! Why not try out our Build a Game in Scratch activity and learn how to create your very own game!
Other posts you may like
We challenged ChatGPT to write an article about Marty the Robot. Read on to find out how it did…
Marty’s New and Improved Sound Functionality
Say hello to Marty’s new drag-and-drop sound blocks. This latest addition to the MartyBlocks coding environment allows you to get creative with your Marty to make a song, record a…
Jump into CSEdWeek with Marty the Robot
Are you looking for new STEM resources for your classroom? Robotical are loaning Marty the Robot to schools for no-obligation, 2 week trials.