





















































Before we create any code, let's make sure we speak the same language.
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.
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:
Let's see if we can get our cat moving:
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.
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.
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.
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.
It's a good practice to get in the habit of saving your work. Save your work early, and save it often:
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.