Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
What is Scratch
Scratch is a fun, easy to use, programming language. Basically, its like scripting your own play. You make
actors perform scripts on a stage. You can make games, art, animations, tell stories, and so much more,
using Scratch.
In programming there are often many ways to accomplish the same task. If you find a new way, great!
We also want to teach you about Computational Thinking, which means, you start thinking like a
programmer. Dont worry about this, it will come naturally.
http://WeCanCodeIT.org
http://WeCanCodeIT.org
Fill out the username and password fields. Make these something memorable to you. Continue by
clicking Next and finishing the registration process by adding your email and other information.
If you need help, then
raiseYourHand();
http://WeCanCodeIT.org
Were almost there! Lets pause for a moment and talk about the odd
way Ive been writing.
At this point, youve seen a few of these statements
If (youveNoticedTheseStatements == true) then
raiseYourHand();
else
keepYourHandDown();
What are some of the things you notice about these statements?
What does this mean to you? How would you say it in English?
http://WeCanCodeIT.org
A computer needs someone to tell it what to do. It needs very specific instructions!
Thats where you come in.
Lets write down some instructions that a computer might understand. When you write this using
English (or any other human language), its called pseudocode.
http://WeCanCodeIT.org
Using pseudocode, lets tell the computer how a person raises her hand.
function raiseYourHand(){
//write your instructions here, between the curly braces.
}
Here is an example:
function raiseYourHand(){
put my arm up, towards the sky;
point fingers to the sky;
if I am called on then
put my arm down to a natural position;
}
Youll notice that sometimes I write my pseudocode with titles like function, and with
parentheses, curly braces, and sometimes semi-colons. This is not required by you. Im just trying
to get you used to other languages people program in besides Scratch.
Your version may differ. This is the fun of programming, you get to make your own recipes!
http://WeCanCodeIT.org
Notice the tip bar on the right. Go ahead and follow along for the next ten to fifteen minutes, and
play with Scratch!
Note: If the tip bar doesnt show, click Tips at the top of the screen, then click Getting Started from
the list that appears.
Tips
Getting Started
Copyright 2014, We Can Code IT, Inc.
http://WeCanCodeIT.org
Youve played around with Scratch, so what are some of the things youve noticed?
Share with the class.
Did you notice colors, stages, actors, commands?
http://WeCanCodeIT.org
Name
your file
Save Now
http://WeCanCodeIT.org
New
If you dont like the cat as your main character, go ahead and choose a new character.
C
l
i
c
k
http://WeCanCodeIT.org
10
Look around and double-click the sprite you like (or single-click, then click OK.)
Next, I want to remove the Cat sprite, so I right-click on the cat, and left-click on delete.
http://WeCanCodeIT.org
11
Step 7: Haunted House Adventure: Move your sprite around with arrows
Drag the
http://WeCanCodeIT.org
12
Lets continue
Click Motion
Drag change y by [10] in to the scripts area,
Attach it underneath the when [up arrow] key pressed block.
Test! Click the up arrow on your keyboard and see what happens.
Motion
y is up and down.
x is left and right.
Think of a number line!
http://WeCanCodeIT.org
13
What is debugging?
Errors in programming are called bugs. We want to catch the bugs in our code as soon as possible.
Debugging is sort of like getting rid of bugs in your house. Theres an interesting story about
how computer bugs were named.
As the story goes, pioneer computer programmer Admiral Grace Murray Hopper coined the
phrase in the early 1940s, when her computer crashed. Searching for the cause of the problem,
Admiral Hopper discovered the original computer bug, inside her computer, was a moth.
As she removed the moth, her coworker asked what she was doing.
Im debugging the machine, she answered.
http://indianapublicmedia.org/amomentofscience/computer-bugs-and-amazing-grace/
http://WeCanCodeIT.org
14
duplicate
Drag the newly-formed set of blocks to an open space in the scripts window, then left-click to place it.
Now, click the drop-down on this duplicated set of blocks, to change when [up arrow] key pressed, to
when [down arrow] key pressed.
http://WeCanCodeIT.org
15
The sprite still moved up when you pressed the down arrow, didnt she? Why?
How do we make her go down? Hint: think of positive numbers as up and right, and negative numbers as
down and left.
Change the value of change y by [10] to the correct number [-10], under the duplicated block.
Test.
http://WeCanCodeIT.org
16
Test
Y is up and down. We dont want to change the Y position when we click the right arrow, we want to
change the X position.
Lets disconnect the change y by . . . motion block from the when right arrow key pressed event
by dragging it away from that block.
Delete the change y by . . . block by right-clicking it, and choosing delete.
delete
Now, attach the change x by . . . block under the when right arrow key pressed event, and leave
the number at 10.
Test!
Copyright 2014, We Can Code IT, Inc.
http://WeCanCodeIT.org
17
http://WeCanCodeIT.org
18
Test!
http://WeCanCodeIT.org
19
A new screen appears. Click the Castle category and double- click a picture of a door.
1) Castle
2)
pick a
scene
3) Click OK
http://WeCanCodeIT.org
20
http://WeCanCodeIT.org
21
http://WeCanCodeIT.org
22
Test.
Move around.
Make sure nothing has changed. Its looking good, but nothing much is happening.
Create an outline of what the witch should do with pseudocode.
Lets forget the programming-like pseudocode weve been using previously, and just write this in basic
English.
When the game starts, start the witch from the top, left corner.
Make sure the witch is shown.
Have the witch glide down a bit for a second.
Have the witch give an ominous warning to start the game for a several seconds.
Have the witch glide up and off the screen for a second.
Ensure the witch is out of sight by hiding her.
Heres what that code looks like in Scratch.
http://WeCanCodeIT.org
23
Make sure the witch sprite is selected, and that you are on the Scripts tab. Then find the blocks above
on your own to make the witch do your bidding!
TEST!
Click the Green Flag to start your game.
Did the witch glide from the left towards the center,
pause and say an ominous greeting,
then glide off to the upper-right of the screen and then disappear?
Why or why not?
Debug or ask for help if you need it!
If its smooth sailing for you, go ahead and try different things.
Examples:
Change the x and y values, then test to see what happens.
Change how many seconds it takes her to glide, or to say her message.
http://WeCanCodeIT.org
24
Make sure your main characters sprite is selected, and you are on the Scripts tab.
Then add the When (flag) clicked event to the scripts view by dragging it on the screen.
Lets set an initial position for the main character first. I set her to x = 170 and y = -90.
Go ahead and try that.
Test by dragging her to a new position on the stage, then clicking the flag. Her position should move to
what you have set on the When flag clicked event.
Variables and objects like sprites are often initialized when a program starts. This sets everything up so
it is ready to be used. Lets continue to set up our main characters actions when flag clicked.
http://WeCanCodeIT.org
25
Step 14: Initialize your main sprite -> Rotation Style & Direction
When you move your main sprite around the screen by pushing the left arrow and right arrow, you may
notice that she doesnt turn to face left, when pressing the left arrow. She may simply walk backwards.
Lets fix that with 3 motion blocks.
TEST!
When you click the green flag to
start the game, then click the
left arrow, does your character
turn to the left now?
When you click the right arrow, does
she turn back to the right?
http://WeCanCodeIT.org
26
Extra Booster
Understanding Rotation Style & Direction in Scratch
Waiting for others? Try this out!
Click on your main sprite, then click on the I icon (circled above). Your window will change to show
some extra options (below).
Try altering the rotation style, and direction. Click your left and right arrows after each change.
What happens?
The code you added from the previous page alters the rotation style and direction of your sprite
programmatically!
http://WeCanCodeIT.org
27
Click
The sprite Im viewing has 4 costumes, each with a distinct name, girl1-a, girl1-b, girl1-c, and girl1-d.
girl1-a
girl1-b
girl1-c
girl1-d
http://WeCanCodeIT.org
28
After you do this, click the Green flag to start your game and TEST!
http://WeCanCodeIT.org
29
After you do this, click the Green flag to start your game and TEST!
http://WeCanCodeIT.org
30
Extra Booster
Adding Music to your game
Waiting for others? Try this out!
Click OK
Copyright 2014, We Can Code IT, Inc.
http://WeCanCodeIT.org
31
Extra Booster
Adding Music to your game (continued)
http://WeCanCodeIT.org
32
Extra Booster
Adding Music to your game (continued)
To add a new broadcast block, click the Scripts tab, then choose Events (brown blocks), and look
towards the bottom for broadcast [message1]. Drag that to the last position in your main characters
when flag clicked blocks.
The name, message1, isnt very
descriptive. Lets change the name of
the broadcasted event.
Click on the arrow next to the dropdown
name message1, and click
new message.
Name it playThemeSong, and click OK.
Next, drag the event called when I receive [] on the screen. Make sure you change the dropdown to
state when I receive [playThemeSong].
Look at the next picture to complete
the process.
Can you figure out
why we add another
broadcast [playThemeSong]
to the end of the
when I receive playThemeSong
event?
Hint: its called an infinite loop for
a reason!
Copyright 2014, We Can Code IT, Inc.
http://WeCanCodeIT.org
33
http://WeCanCodeIT.org
34
http://WeCanCodeIT.org
35
After you place the block, make sure to change the name of the broadcasted event.
Click on the arrow next to the broadcast dropdown, and click new message.
Name it findKey and click OK.
http://WeCanCodeIT.org
36
Add the Looks block called think [text] for (a number) secs on to when I receive findKey block.
http://WeCanCodeIT.org
37
TEST!
Is it working as expected? If not, here are some common issues:
Pseudocode Time!
How do we know when our main sprite has found the key?
What Sensing blocks might signal that the key has been found.
What sprite should hold this information?
Where could we make the broadcast to
start being aware that the girl is touching the key?
http://WeCanCodeIT.org
38
Step 22: Add Event Listener (when I receive [findKey]) to the Key Sprite
Did your pseudocode read something like this?
Add a when I receive findKey to the key element to start off the process of waiting to be found.
Wait until the girl is touching the key.
After the girl touches the key then do something else (like change scenes).
Use the colors of the blocks as guides to which Script category under which the blocks are listed.
You probably dont have castle4 added as a backdrop.
Go ahead and add a new backdrop. It may or may not
be castle4. I am switching mine to that because it looks
like the eerie interior of a haunted house. Feel free to
choose one of your liking.
Waiting around? Feel free to add a sound, like a door creak! Click the Sounds tab when you are on the
Key sprite to and choose a sound you want to play. After it is in your Sounds tab, you can add it to the
Keys findKey event listener (when I receive findKey) by clicking the Scripts tab, then looking under the
Sound category.
http://WeCanCodeIT.org
39
What do you want to have happen next? Should a ghost fly by, like the witch did?
Do you want to have the Sprite look for other objects, like when she looked for and
found the key?
Good Luck, have fun, and discover more about following people, sharing your project,
adding your own artwork and more in the remainder of this workbook!
http://WeCanCodeIT.org
40
http://WeCanCodeIT.org
41
share
Instructions
After you click Share, you will end up on your project page. Fill out the instructions, as well as the
Notes and Credits. If you are building off of someone elses project, its important to give them credit.
You would want the same, right?
http://WeCanCodeIT.org
42
Click
Click
http://WeCanCodeIT.org
43
Click
http://WeCanCodeIT.org
44
Project Page
You can Share your project outside of Scratch with your friends by clicking Embed, and giving them the
URL of your project page. You can also add your project to Facebook, Twitter, or even code in a Web
Page from the Embed area.
Special
Embed
code for
web
sites.
http://WeCanCodeIT.org
45
http://WeCanCodeIT.org
46
Click
the
Folder
Icon
Click the New sprite: folder icon.
Choose a file you want to upload from your computer, and double-click on it to start the upload.
http://WeCanCodeIT.org
47
Test.
You may want to delete the original sprite by right-clicking on that sprite and choosing delete.
Warning: when copying one sprites code to another, if you dont delete the original sprite, you may
have code that is run twice when you would only like it to run once. Make sure to review and test.
http://WeCanCodeIT.org
48
Keep Coding!
Links to We Can Code IT
Please follow us and spread the word by sharing our posts!
Web: http://WeCanCodeIT.org
Facebook: http://facebook.com/WeCanCodeIT
Twitter: http://twitter.com/WeCanCodeIT
Follow us on Scratch: http://mit.scratch.edu/users/WeCanCodeIT
Email us at hello@WeCanCodeIT.org
We have monthly workshops. Sign up for our newsletter online to get all the info!
We Can Code IT is a non-profit organization.
If you would like to donate money, time, and/or computers, visit us online, or call
844-WeCanCodeIT
http://WeCanCodeIT.org
49