Coding with Scratch
Creating flexible interactive resources
What is coding?
Coding, or computer programming, is writing instructions for the computer to make it do certain things.
Practically, it is useful for automating tasks, customising computer actions to suit exactly what you need to do, and finding solutions to problems.
In terms of skills, coding is good for logic and problem solving, as well as creativity and planning.
For more on what coding is and why to try it out, see our Coding Skills Guide.
Have you done any coding before?
Block-based coding
Using a jigsaw-like interface to drag and drop sections of code together from a selection of pieces.
Good if you want to create things quickly and learn key coding concepts without a steep learning curve.
Also useful for less confident typists as it removes the initial barrier of typos making coding difficult to get into.
Introduction to Scratch
What is Scratch?
Scratch (scratch.mit.edu) is a web-based coding platform designed specifically for education and young people, by the MIT Media Lab.
It uses 'block-based' coding - where code isn't typed, but it fitted together like Lego blocks.
It was designed for use by 8 - 16 year olds, but is also ideal for learning coding skills and creating projects regardless of your age.
You can share the things you create so other people can use them and also 'remix' them to edit a copy of the code themselves.
Why learn Scratch?
Great starting point for learning coding.
Good if you want to create things other people can interact with easily - like games and stories.
Useful in education contexts as it is used widely in schools and coding clubs (and is designed with learners in mind).
Easy to add custom characters, background images, and sounds.
Can use skills to go on to learn typed coding languages, or build apps using block based coding with MIT App Inventor or Thunkable.
How does Scratch work?
You control one or more 'sprites', which are basically characters on the screen (these can be the ones they provide, or you can create your own).
The code is in set 'blocks' that you slot together to control the sprite.
You can also include other elements like storing values, user input, and other kinds of media like sound effects.
Exercise A
Exercise A on the exercise sheet - getting set up with Scratch and trying out examples
You need a free account to create and share your Scratch projects - sign up at https://scratch.mit.edu/
The aim of this exercise is to start getting familiar with the Scratch interface and what other people have done with the tool.
We recommend taking some time to explore other people's Scratch projects, and to 'see inside' to look at their Scratch code.
Key concepts in Scratch
Sprites and backdrops
The first part of coding in Scratch (and in other drag and drop tools) is setting up the elements you want to work with.
Scratch has 'sprites' which are the on-screen objects that can be controlled, and 'backdrops', which you can set and also change with code.
You can choose built-in sprites and backdrops, or you can draw or upload your own.
Code blocks
Scratch works by controlling what happens on your 'stage' (the area with the backdrop and sprites) using code blocks.
The blocks you can use all appear on the pane on the left hand side of Scratch - drag and drop them onto the centre of the screen and then slot them together to make the code work.
Costumes and sounds
On the left hand pane you can also add sprite 'costumes' and sounds.
This allows you to add extra features, including animation and sound effects.
Different 'costumes' can be changed with code, meaning you could have different views of the sprite, or facial expressions.
Events
Code can only run when it is told it should run!
In Scratch, 'event' blocks allow you to tell chunks of code when to run.
You can use multiple events for one sprite - good for having different chunks of code to do different things.
Control
'Control' blocks are ones that mean you can control what the code itself does, rather than have an effect on the user interface.
For example, there are 'wait' blocks to add pauses to your code - otherwise code will run immediately after one another, which can mess up animations!
Scratch also allows you to repeat actions, either a certain number of times, forever, or until a certain condition is true.
And it can make decisions by asking if a condition is true, run some more code blocks.
Variables
Variables are a way of storing values in your code, so they can be used.
The most common way to use a variable in Scratch is to create a score of some kind for a game or quiz.
You create the variable in Scratch using the Variables blocks, then choosing 'Make a Variable' and giving it a name. Then you can use the blocks in your code to set the variable to a certain value or change the value.
Making your own Scratch project
What could you make in Scratch?
The Scratch examples may have given you ideas about what is possible in Scratch, but there's all sorts of things you can make - the limits are the blocks available (though there are extra options there) and your imagination!
A good starting project is to try creating a simple story, displaying text on screen, and then adapting it so that users can input their own words into the story (e.g. the main character's name).
Or you might want to try and create an animation, which can start with simple movement and then be extended with other features like size or costume change.
How to get started
For example...
Goal: make a character say something when you click on them
Steps:�Click on sprite�Display text on screen
Event block: When this sprite is clicked
Looks block: Say 'I am talking' for 3 seconds
https://scratch.mit.edu/projects/401949661/
Troubleshooting
Everyone who does any kind of coding will often need to troubleshoot errors!
If your code doesn't do what you expect when you hit the 'run' button, there a few things to check:
Exercises
Play the quiz example, then 'remix' it to make your own quiz.
Make your own Scratch project from...scratch!
Further resources
Our Coding Skills Guide has guidance on getting started with coding, choosing what to learn, and resources for specific coding languages. If you liked Scratch but want to make things a bit more app-like, look at the Thunkable section.
Scratch's Tutorials allow you to learn Scratch skills and create specific projects.
There are various free online courses on Scratch - the Raspberry Pi Foundation has created one on FutureLearn which is aimed at people teaching children to code, but which is useful for learning the basics of Scratch too.