2ND Scratch-Programming
2ND Scratch-Programming
• Move: This function moves the sprite a certain number of steps in the direction it is facing. You can
specify the number of steps to move.
• Turn: This function rotates the sprite clockwise or counterclockwise by a specified number of degrees.
• Go to x: y:: This function moves the sprite to a specific position on the stage, with the coordinates
(0,0) representing the center of the stage.
• Glide: Glide allows the sprite to smoothly move to a specified position on the stage over a specified
duration of time.
• Point in direction: This function sets the direction the sprite is facing to a specified angle.
• Set rotation style: This function sets how the sprite rotates when it moves. You can choose between
"don't rotate," "all around," and "left-right."
• Change x by: This function moves the sprite horizontally by a specified number of
pixels.
• Change y by: This function moves the sprite vertically by a specified number of
pixels.
• If on edge, bounce: This function makes the sprite bounce off the edges of the
stage when it reaches them.
• Set x to: This function sets the sprite's horizontal position to a specific value.
• Set y to: This function sets the sprite's vertical position to a specific value.
• Go to front/back layer: This function moves the sprite to the front or back layer of
the stage, affecting its visibility when overlapped with other sprites.
LOOKS FUNCTION
• Switch Costume: This function allows a sprite to change its appearance by switching to a
different costume. Each sprite can have multiple costumes, which are different images or
drawings.
• Next Costume: This function switches the sprite to the next costume in its costume list. If
the current costume is the last one, it will switch back to the first costume.
• Say: This function displays a speech bubble containing text above the sprite's head for a
specified duration.
• Think: Similar to "Say," this function displays a thought bubble containing text above the
sprite's head for a specified duration.
• Say for X seconds: This function displays text in a speech bubble above the sprite's head for a
specific duration specified in seconds.
• Think for X seconds: Similar to "Say for X seconds," this function displays text in a thought
bubble above the sprite's head for a specific duration specified in seconds.
• Change Size by: This function increases or decreases the size of the sprite by a specified
amount.
• Set Size to: This function sets the size of the sprite to a specific value, either increasing or
decreasing its size to match the given value.
• Show: This function makes the sprite visible on the stage if it was previously hidden.
• Hide: This function hides the sprite from view on the stage.
• Go to Front: This function brings the sprite to the front layer, making it appear in front of
other sprites on the stage.
• Go Back [x] Layers: This function moves the sprite back a specified number of layers,
placing it behind other sprites on the stage.
• Clear Graphic Effects: This function removes any graphic effects applied to the sprite, such
as color, brightness, fisheye, etc.
SOUNDS FUNCTION
• Play Sound: This function plays a specific sound attached to the sprite or the stage.
You can choose from the available sounds in the Scratch library or upload your own
sound files.
• Stop All Sounds: This function stops all currently playing sounds in the project.
• Play Sound Until Done: This function plays a sound and waits for it to finish playing
before executing the next block in the script.
• Set Volume to: This function sets the volume level for all sounds in the project. The
volume level can range from 0% (silent) to 100% (maximum volume).
• Change Volume by: This function increases or decreases the volume level by a
specified amount.
• Set Instrument to: This function changes the instrument used to play sounds.
Scratch provides a variety of instruments, such as piano, trumpet, drum, etc.
• Change Tempo by: This function changes the tempo (speed) of all sounds in the
project by a specified amount.
• Set Tempo to: This function sets the tempo (speed) of all sounds in the project
to a specific value.
• Start Sound [sound_name]: This function plays a specific sound by its name.
This is useful when you have custom sounds uploaded to your project.
• Wait [x] Seconds: This function pauses the execution of the script for a
specified duration, allowing you to create timing and synchronization with
sound effects.
• Play Drum [drum_type]: This function plays a drum sound based on the
specified drum type. Scratch provides various drum types such as snare, bass,
tom, etc.
EVENTS
• When Flag Clicked: This block triggers its attached script when the green
flag in the Scratch interface is clicked, starting the execution of the
program.
• When [Key] Pressed: This block triggers its attached script when a specific
key on the keyboard is pressed. You can choose from a variety of keys, such
as space, arrow keys, letters, and numbers.
• When Sprite Clicked: This block triggers its attached script when the sprite
to which it is attached is clicked by the mouse pointer.
• When Stage Clicked: This block triggers its attached script when the stage
(background) is clicked by the mouse pointer.
• When [Color] Touched: This block triggers its attached script when the
sprite to which it is attached touches a specific color on the stage.
• When [Sprite] Bumps [Sprite]: This block triggers its attached script when
one sprite collides with another sprite on the stage.
• When [Sprite] Is Dragged: This block triggers its attached script when the
sprite to which it is attached is dragged by the mouse pointer.
• When I Receive [Message]: This block triggers its attached script when the
sprite receives a broadcast message from another sprite or the stage.
• Broadcast [Message]: This block sends a broadcast message to all sprites in
the project. Sprites that have scripts with a "When I Receive [Message]" block
for the specified message will execute their attached scripts.
• Broadcast [Message] and Wait: This block sends a broadcast message to all
sprites in the project and pauses the execution of the current script until all
sprites have finished executing their scripts in response to the broadcast
message.
CONTROL FUNCTION
• Wait [x] Seconds: This block pauses the execution of the script for a
specified duration in seconds before continuing to the next block.
• Repeat [x]: This block repeats its attached script a specified number of
times.
• Forever: This block repeats its attached script indefinitely, until the
program is stopped or the green flag is clicked.
• If [condition] then: This block checks a condition, and if it's true, it
executes its attached script.
• If [condition] then else: This block checks a condition, and if it's true, it
executes the first attached script; otherwise, it executes the second
attached script.
• Wait Until [condition]: This block pauses the execution of the script until
the specified condition becomes true.
• Stop [all/sprite]: This block stops the execution of the entire program (if "all" is selected) or just the
sprite's scripts (if "sprite" is selected).
• Stop [this script/other scripts in sprite]: This block stops the execution of the script to which it is
attached (if "this script" is selected) or all other scripts belonging to the same sprite (if "other scripts in
sprite" is selected).
• Stop All: This block stops the execution of all scripts and broadcasts in the project.
• When I Start as a Clone: This block triggers its attached script when a clone of the sprite is created.
• Create Clone of [Myself]: This block creates a clone of the sprite, which starts executing its own
scripts independently.
• Delete This Clone: This block deletes the clone of the sprite to which it is attached.
SENSING FUNCTION
• Touching [Color]: This block checks if the sprite is touching a specific color on the stage.
You can use this block to detect collisions between sprites or between a sprite and a
colored backdrop.
• Touching [Sprite]: This block checks if the sprite is touching another sprite on the stage.
It's commonly used to detect collisions between sprites.
• Color [Color] is Touching [Color]: This block checks if one color is touching another color
on the stage. It's useful for detecting interactions between different elements of the
backdrop.
• Ask [Question] and Wait: This block displays a dialog box with a question and waits for the
user to input a response. The response can then be stored in a variable and used in your
program.
• Key [Key] Pressed?: This block checks if a specific key on the keyboard is currently
pressed. You can use this block to detect keyboard input from the user.
• Mouse Down?: This block checks if the mouse button is currently pressed. It's commonly
used to detect mouse clicks or drag events.
• Mouse X/Y: These blocks return the current x and y coordinates of the mouse pointer on the stage.
You can use these blocks to track the position of the mouse cursor.
• Distance to [Sprite]: This block calculates the distance between the sprite and another sprite on the
stage. It's commonly used for proximity-based interactions between sprites.
• Reset Timer: This block resets the internal timer used by Scratch to measure time elapsed since the
project started or since the last reset.
• Timer: This block returns the current value of the internal timer, representing the time elapsed
since the project started or since the last reset.
• Timer [Timer] > [Value]: This block checks if the value of a specific timer is greater than a specified
value. It's commonly used for timing-based events and interactions.
• [Variable] > [Value]: This block checks if the value of a variable is greater than a specified value. It's
commonly used for comparing numerical values in conditional statements.
OPERATORS
• + (Addition): This block adds two numbers together and returns the result.
• - (Subtraction): This block subtracts one number from another and returns the result.
• × (Multiplication): This block multiplies two numbers together and returns the result.
• / (Division): This block divides one number by another and returns the result. Note that division by
zero results in an error.
• Mod (Modulo): This block returns the remainder of dividing one number by another.
• Random [x] to [y]: This block generates a random number within a specified range.
• = (Equal to): This block checks if two values are equal and returns true if they are, otherwise it
returns false.
• < (Less than): This block checks if one value is less than another and returns true if it is, otherwise
it returns false.
• > (Greater than): This block checks if one value is greater than another and
returns true if it is, otherwise it returns false.
• And: This block performs a logical AND operation on two boolean values and
returns true if both are true, otherwise it returns false.
• Or: This block performs a logical OR operation on two boolean values and
returns true if at least one of them is true, otherwise it returns false.
• Not: This block negates a boolean value, returning true if the input is false, and
false if the input is true.
• Join [text1] [text2]: This block concatenates two pieces of text together.
• Letter [n] of [text]: This block returns the nth letter of a text string.
• Length of [text]: This block returns the number of characters in a text string.
VARIABLES
• Make a Variable: This block allows you to create a new variable. You can give the
variable a name and choose whether it should be a global variable (accessible by all
sprites) or a sprite variable (accessible only by the sprite that created it).
• Set [variable] to [value]: This block sets the value of a variable to a specific value.
You can use this block to initialize variables or update their values during the
execution of your program.
• Change [variable] by [value]: This block increments or decrements the value of a
variable by a specified amount. It's commonly used for counting, scoring, or
tracking changes over time.
• Show Variable [variable]: This block displays the value of a variable on the stage.
You can choose to show the variable as a sprite overlay or in the stage's display
area.
• Hide Variable [variable]: This block hides the display of a variable on the stage.
• Variable [variable]: This block returns the current value of a variable. You can use this
block in mathematical operations, conditional statements, or as input to other blocks.
• (Sprite) Variable [variable]: This block returns the value of a sprite-specific variable. It's
only accessible within the scripts of the sprite that created the variable.
• (Stage) Variable [variable]: This block returns the value of a global variable. It's accessible
by all sprites in the project.
• (Delete) All Variables: This block deletes all variables from memory. Use with caution, as
this action cannot be undone.
• (Show/Hide) Variable [variable]: This block toggles the visibility of a variable on the stage,
showing it if it's hidden and hiding it if it's shown.
CUSTOM BLOCKS
• Define: This block is used to define a new custom block. When you drag this block into the
scripting area, you can give your block a name and specify its parameters, which are inputs
to the block's code.
• Run: This block is used to call (or invoke) a custom block that you've defined elsewhere in
your project. When you drag this block into the scripting area, you can select the custom
block you want to run from a dropdown list.
• Input Parameters: Custom blocks can have input parameters, which are placeholders for
values that you can pass to the block when you call it. Input parameters make your custom
blocks more flexible and reusable, allowing them to perform different actions depending on
the values you provide.
• Output: Custom blocks can also have output values, which are values that the block can
return to the part of your program that called it. Output values allow custom blocks to
communicate results or information back to the rest of your program.
• Modularity: Custom blocks promote modularity by allowing you to break
down complex tasks into smaller, more manageable pieces of code. You
can then combine these smaller blocks into larger, more complex
behaviors by calling them from other parts of your program.
• Reuse: Custom blocks encourage code reuse by allowing you to define
common tasks or procedures once and then use them multiple times
throughout your project. This reduces duplication of code and makes
your project easier to maintain and modify.
• Organization: Custom blocks improve code organization by providing a
way to encapsulate related code into cohesive units. This makes it easier
to understand and maintain your project's codebase, especially as it
grows in complexity.