Before we create any code, let’s make sure we speak the same language.
The interface at a glance
When we encounter software that’s unfamiliar to us, we often wonder, “Where do I begin?” Together, we’ll answer that question and click through some important sections of the Scratch interface so that we can quickly start creating our own projects.
Now, open Scratch and let’s begin.
Time for action – first step
When we open Scratch, we notice that the development environment roughly divides into three distinct sections, as seen in the following screenshot. Moving from left to right, we have the following sections in sequential order:
- Blocks palette
- Script editor
Let’s see if we can get our cat moving:
- In the blocks palette, click on the Looks button.
- Drag the switch to costume block onto the scripts area.
- Now, in the blocks palette, click on the Control button.
- Drag the when flag clicked block to the scripts area and snap it on top of the switch to costume block, as illustrated in the following screenshot.
How to snap two blocks together?
As you drag a block onto another block, a white line displays to indicate that the block you are dragging can be added to the script. When you see the white line, release your mouse to snap the block in place.
- In the scripts area, click on the Costumes tab to display the sprite’s costumes.
- Click on costume2 to change the sprite on the stage. Now, click back on costume1 to change how the sprite displays on the stage.
- Directly beneath the stage is a sprites list. The current list displays Sprite1 and Stage.
- Click on the sprite named Stage and notice that the scripts area changes. Click back on Sprite1 in the sprites list and again note the change to the scripts area.
- Click on the flag above the stage to set our first Scratch program in motion. Watch closely, or you might miss it.
What just happened?
Congratulations! You created your first Scratch project. Let’s take a closer look at what we did just now.
As we clicked through the blocks palette, we saw that the available blocks changed depending on whether we chose Motion, Looks, or Control. Each set of blocks is color-coded to help us easily identify them in our scripts.
The first block we added to the script instructed the sprite to display costume2. The second block provided a way to control our script by clicking on the flag.
Blocks with a smooth top are called hats in Scratch terminology because they can be placed only at the top of a stack of blocks.
Did you look closely at the blocks as you snapped the control block into the looks block? The bottom of the when flag clicked block had a protrusion like a puzzle piece that fits the indent on the top of the switch to costume block.
As children, most of us probably have played a game where we needed to put the round peg into the round hole. Building a Scratch program is just that simple. We see instantly how one block may or may not fit into another block.
Stack blocks have indents on top and bumps on the bottom that allow blocks to lock together to form a sequence of actions that we call a script.
A block depicting its indent and bump can be seen in the following screenshot:
When we clicked on the Costumes tab, we learned that our cat had two costumes or appearances. Clicking on the costume caused the cat on the stage to change its appearance.
As we clicked around the sprites list, we discovered our project had two sprites: a cat and a stage. And the script we created for the cat didn’t transfer to the stage.
We finished the exercise by clicking on the flag. The change was subtle, but our cat appeared to take its first step when it switched to costume2.
Basics of a Scratch project
Inside every Scratch project, we find the following ingredients: sprites, costumes, blocks, scripts, and a stage. It’s how we mix the ingredients with our imagination that creates captivating stories, animations, and games.
Sprites bring our program to life, and every project has at least one. Throughout the book, we’ll learn how to add and customize sprites.
A sprite wears a costume. Change the costume and you change the way the sprite looks. If the sprite happens to be the stage, the costume is known as a background.
Blocks are just categories of instructions that include motion, looks, sound, pen, control, sensing, operators, and variables.
Scripts define a set of blocks that tell a sprite exactly what to do. Each block represents an instruction or piece of information that affects the sprite in some way.
We’re all actors on Scratch’s stage
Think of each sprite in a Scratch program as an actor. Each actor walks onto the stage and recites a set of lines from the script. How each actor interacts with another actor depends on the words the director chooses. On Scratch’s stage, every object, even the stone in the corner, is a sprite capable of contributing to the story.
As directors, we have full creative control.
Time for action – save your work
It’s a good practice to get in the habit of saving your work. Save your work early, and save it often:
- To save your new project, click the disk icon at the top of the Scratch window or click File | Save As.
- A Save Project dialog box opens and asks you for a location and a New Filename.
- Enter some descriptive information for your project by supplying the Project author and notes About this project in the fields provided.
Set the cat in motion
Even though our script contains only two blocks, we have a problem. When we click on the flag, the sprite switches to a different costume and stops. If we try to click on the flag again, nothing appears to happen, and we can’t get back to the first costume unless we go to the Costumes tab and select costume1. That’s not fun.
In our next exercise, we’re going to switch between both costumes and create a lively animation.