Scratch Code Index
Table of Contents
Scratch blocks
Motion
Looks
Sound
Events
Control
Sensing
Operators
Sample blocks
Move up/down/right/left
Jump
When sprite touches another sprite, do something
Bounce sprite left and right
Bounce sprite off of all 4 walls
Scratch blocks
Motion
Block What does it do?
Moves the sprite by the specified number of
pixels in the current direction
Rotates the sprite to the right by the
specified number of degrees
Rotates the sprite to the left by the specified
number of degrees
Places the sprite at a random position
Places the sprite at the specified x and y
position
Moves the sprite to a random position, for
the specified number of seconds.
The bigger the number, the slower the sprite
moves.
Moves the sprite to the specified x and y
position, for the specified number of seconds.
The bigger the number, the slower the sprite
moves.
Rotates the sprite to face the specified
direction.
Rotates the sprite to face the mouse pointer,
or another sprite.
Moves the sprite horizontally by the specified
number.
A positive number will move the sprite to the
right. A negative number will move the sprite
to the left.
Moves the sprite horizontally to the specified
x position,
Moves the sprite vertically by the specified
number.
A positive number will move the sprite up. A
negative number will move the sprite down.
Moves the sprite vertically to the specified y
position,
If the sprite is touching any of the 4 edges of
the screen, then bounces the sprite off of the
edge.
Changes the rotation style of the sprite (the
default is “all around”).
- all around: The sprite can face any
direction
- left-right: The sprite can only face
left or right (any other directions are
rounded)
- don't rotate: The sprite always faces
in one direction
Select each checkbox to show the value for
the current sprite on the screen.
Looks
Block What does it do?
Sprite will have speech bubble that says “Hello” for 2
seconds
Sprite will have speech bubble that says “Hello” forever or
until you add stop code
Sprite will have think bubble that says “Hmm…” for 2
seconds
Sprite will have think bubble that says “Hmm…” forever or
until you add stop code
Sprite will change to a specific costume of your choice
Sprite will change to the next costume
Background will change to a specific background of your
choice
Background will change to the next background
Sprite will change size by the specified number of units
Sprite will change size to the specified percentage of the
current size
Sprite will change color by certain units
Sprite will change to specific color
Reset Sprite to original color, clear any effects on your
Sprite
Shows the sprite (Sprite will appear)
Hides the sprite (Sprite will disappear)
Sprite will move all the way forward (in front of all Sprites)
or backwards (behind all Sprites)
Sprite will move forward (in front of one Sprite) or
backwards (behind one Sprite)
Select the checkbox to show the costume number or name
on the screen.
Select the checkbox to show the backdrop number or name
on the screen.
Select the checkbox to show the size of the current sprite
on the screen.
Sound
Block What does it do?
Sprite plays the specified sound, fully
Sprite starts playing the specified sound
Stops all sounds
Changes the pitch by the specified number of
units
Sets the pitch to the specified pitch
Clears sound effects of this sprite
Change the volume by the specified amount
(increase with +, decrease with -)
Sets the volume to the specified percent
Select the checkbox to show the current
volume on the screen
Events
Block What does it do?
When the “Go” flag is clicked, starts the
sequence of blocks.
When the specified key is pressed, starts the
sequence of blocks.
When the current sprite is clicked, starts the
sequence of blocks.
When the background changes to the
selected backdrop, starts the sequence of
blocks.
Once the loudness is greater than the
specified number, starts the sequence of
blocks.
For more info on loudness, see the Sound
section.
Once the timer is greater than the specified
number, starts the sequence of blocks.
For more info on timer, see the Sensing
section.
When the current sprite receives the
specified message, starts the sequence of
blocks.
Sends the specified message to all scripts in
the program.
Sends the specified message to all scripts in
the program, and waits until all scripts
receive and respond to the message.
Control
Block What does it do?
Waits the specified number of seconds before
executing the next block.
Repeats the inner chain of blocks the specified
number of times.
Repeats the inner chain of blocks forever.
If the specified condition is true, then executes the
inner chain of blocks.
For possible conditions, see the Sensing or
Operators sections.
If the specified condition is true, then executes the
first chain of blocks.
If the specified condition is false, then executes the
second chain of blocks.
For possible conditions, see the Sensing or
Operators sections.
Waits for the specified condition to be true, before
executing the next block.
For possible conditions, see the Sensing or
Operators sections.
As soon as the specified condition is true, starts
executing the inner chain of blocks.
As soon as the specified condition is false, stops
executing the chain of blocks.
For possible conditions, see the Sensing or
Operators sections.
Stops all scripts for the current sprite.
Stops the current chain of blocks.
Stops all scripts for the current sprite, except for
the current chain of blocks.
Every time a clone of the current sprite is first
created, starts the sequence of blocks.
Creates a clone of the current sprite.
Deletes the current clone of the current sprite.
Sensing
Block What does it do?
True if the sprite is touching the
mouse-pointer, the edge, or another sprite.
False otherwise.
True if the sprite is touching the specified
color. False otherwise.
True if the 1st color is touching the 2nd color.
False otherwise.
Calculates the distance from the mouse
pointer to a specific sprite in pixels
The sprite will ask the question and wait for
the user (the person playing the game) to
enter an answer.
Select the checkbox to show the answer on
the screen.
Checks if a specific key is pressed - true if
the key is pressed, false otherwise
Checks if the mouse is clicked - true if the
mouse is clicked, false otherwise
The x position of the mouse pointer.
The y position of the mouse pointer.
Makes the sprite draggable or not draggable.
Select the checkbox to show the loudness
(sound volume) on the screen.
Select the checkbox to show the timer value
on the screen.
Resets the timer.
The block will report a specified value of the
specified sprite or stage
Select the checkbox to show the selected
part of the current date & time on the screen.
The number of days between the year 2000
and the current day.
Select the checkbox to show the current
username on the screen.
Operators
Block What does it do?
The result of adding the 2 numbers
The result of subtracting the 2nd number
from the 1st number
The result of multiplying the 2 numbers
The result of dividing the 1st number with
the 2nd number
A random number that is greater than or
equal to the 1st number, and less than or
equal to the 2nd number
True if the 1st number is greater than the
2nd number. False otherwise.
True if the 1st number is less than the 2nd
number. False otherwise.
True if the 2 numbers are the same. False
otherwise.
True if both conditions are true. False
otherwise.
True if at least 1 of the 2 conditions are true.
False otherwise.
Reverses the value of the condition. True if
the condition is false. False otherwise.
The result of linking the 2 values together.
(Example: join “apple” and “banana” →
“applebanana”)
The N-th letter of the given value.
(Example: letter 1 of “apple” is “a”)
The number of letters in the given value.
(Example: length of “apple” is 5)
True if the 1st value contains the 2nd value.
False otherwise.
(Example: “apple” contains “a” is true. “apple”
contains “b” is false.)
The remainder after dividing the 1st number
by the 2nd number
(Example: 10 mod 3 is 1)
Rounds the given number to the nearest
whole number
(Example: 1.3 rounds to 1)
Applies the selected function to the given
number.
Sample blocks
Move up/down/right/left
Whenever the up arrow is pressed, move the sprite up by 4 pixels.
Whenever the down arrow is pressed, move the sprite down by 4 pixels.
Whenever the right arrow is pressed, move the sprite right by 4 pixels.
Whenever the left arrow is pressed, move the sprite left by 4 pixels.
Jump
Whenever the space key is pressed, make the sprite jump:
When sprite touches another sprite, do something
Whenever the current sprite touches an Apple sprite, increase the score by 1.
Bounce sprite left and right
Bounce sprite off of all 4 walls