Eight Categories of Scratch Blocks

Scratch provides access to over 100 code blocks. These code blocks are organized into eight categories and are made available on the blocks palette. Each of these categories of code blocks is described in the following list:

  • Motion. Code blocks that control sprite placement, direction, rotation, and movement.

  • Looks. Code blocks that affect sprite and background appearance and provide the ability to display text.

  • Sound. Code blocks that control the playback and volume of musical notes and audio files.

  • Pen. Code blocks that can be used to draw using different colors and pen sizes.

  • Control. Code blocks that trigger script execution based on predefined events, repeatedly execute programming logic using loops, and perform conditional logic.

  • Sensing. Code blocks that can be used to determine the location of the mouse-pointer, its distance from other sprites, and whether a sprite is touching another sprite.

  • Numbers. Code blocks that perform logical comparisons, rounding, and other arithmetic operations.

  • Variables. Code blocks that can be used to store data used by applications when they execute.

You can view the code blocks belonging to a given category by clicking on one of the eight labeled button controls at the top of the blocks palette. Note that each category of code block is color coded, making it easy to distinguish between code blocks from different categories.

Each of these categories of code blocks is reviewed in the sections that follow. This review covers Scratch’s entire collection of code blocks, indicating which ones support monitors and providing a brief description of each block’s usage.

Moving Objects Around the Drawing Canvas

Motion blocks control a sprite’s placement on the stage. Motion blocks are colored blue. There are motion blocks that let you set the direction a sprite will move and then other blocks to move them. There are also motions blocks that report on a sprite’s location and direction. Table 3.1 outlines all of the code blocks that fit into this category.

Table 3.1. Scratch Motion Blocks
BlockMonitorDescription
NoMoves a sprite forward or backwards a specified number of steps.
NoRotates a sprite a specified number of degrees in a clockwise direction.
NoRotates a sprite a specified number of degrees in a counterclockwise direction.
NoPoints a sprite toward a specified direction (0 = up, 90 = right, –90 = left, 180 = down).
NoPoints a sprite toward either the mouse-pointer or a specified sprite.
NoMoves a sprite to a specified coordination location on the stage.
NoMoves a sprite to the location of either the mouse-pointer or another sprite.
NoMoves a sprite to the specified coordinate position over a specified number of seconds.
NoChanges the position of a sprite on the X-axis by a specified number of pixels.
NoChanges a sprite’s location on the X-axis to a specified value.
NoChanges the position of a sprite on the Y-axis by a specified number of pixels.
NoChanges a sprite’s location on the Y-axis to a specified value.
NoChanges a sprite’s direction when it makes contact with one of the edges of the stage.
YesRetrieves a value representing a sprite’s coordinate on the X-axis (between –240 and 240).
YesRetrieves a value representing a sprite’s coordinate on the Y-axis (between –180 and 180).
YesRetrieves a value representing a sprite’s current direction (0 = up, 90 = right, –90 = left, 180 = down).

You will learn more about motion blocks in Chapter 5, “Moving Things Around.”

Changing Object Appearance

Looks blocks modify sprite and background appearance and display text within popup bubbles. Looks blocks are colored purple. There are looks blocks that let you modify sprite costumes and colors. There are also blocks that let you modify a sprite’s size and control whether a sprite is visible on the stage. Table 3.2 outlines all of the code blocks that fit into this category.

Table 3.2. Scratch Looks Blocks
BlockMonitorDescription
NoChanges a sprite’s costume, modifying its appearance.
NoChanges a sprite’s costume to the next costume in the sprite’s costume list, jumping back to the beginning of the list when the end of the list is reached.
YesRetrieves a numeric value representing a sprite’s current costume number.
NoDisplays a text message in a speech bubble for a specified number of seconds.
NoDisplays a text message in a speech bubble or removes the display of a speech bubble when no text is specified.
NoDisplays a text message in a thought bubble for a specified number of seconds.
NoDisplays a text message in a thought bubble or removes the display of a thought bubble when no text is specified.
NoModifies a sprite’s appearance by applying and modifying a special effect (color, fisheye, whirl, pixelate, mosaic, brightness, or ghost) by a specified numeric value.
NoApplies a special effect (color, fisheye, whirl, pixelate, mosaic, brightness, or ghost) to a sprite by a specified numeric value.
NoRestores a sprite to its normal appearance, removing any special effects that may have been applied.
NoModifies the size of a sprite by a specified numeric amount.
NoSets a sprite’s size to a percentage of its original size.
YesRetrieves a percentage value representing a sprite’s current size when compared to its original size.
NoTells Scratch to display a sprite.
NoSuppresses the display of a sprite on the stage, preventing it from interacting with other sprites.
NoPlaces a sprite on top of other sprites, placing it on the top layer and ensuring its display.
NoMoves a sprite back a specified number of layers, allowing other sprites to be displayed on top of it.
NoAlters the stage’s appearance by assigning it a different background.
NoChanges the stage’s background to the next background in the background list.
NoRetrieves a numeric value representing the background number of the stage’s current background.

You will learn more about looks blocks in Chapter 10, “Changing the Way Sprites Look and Behave.”

Making Some Noise

Sound blocks play music and add sound effects to your Scratch application projects. Sound blocks are colored pink. There are sound blocks that let you play sounds and drum beats, select different types of instruments, control playback volume, and modify tempo. Table 3.3 outlines all of the code blocks that fit into this category.

Table 3.3. Scratch Sound Blocks
BlockMonitorDescription
NoPlays the specified sound file while allowing the script file in which it is inserted to keep executing.
NoPlays the specified sound file, pausing script execution until the sound file has finished playing.
NoHalts the playback of any sound files currently being played.
NoPlays a drum sound selected from the block’s pull-down menu a specified number of seconds.
NoPauses sound playback for a specified number of beats.
NoPlays a musical note selected from the block’s pull-down menu a specified number of beats.
NoSpecifies the instrument to be used when playing musical notes.
NoChanges a sprite’s volume by a specified value.
NoSets a sprite’s sound volume to a specified percentage level.
YesRetrieves a numeric value representing a sprite’s sound volume.
NoAlters a sprite’s tempo by a specified number of beats per minute.
NoAssigns the number of beats per minute to be used as a sprite’s tempo.
YesRetrieves a numeric value representing a sprite’s tempo.

You will learn more about sound blocks in Chapter 11, “Spicing Things Up with Sounds.”

Drawing Lines and Shapes

Pen blocks draw any combination of shapes and lines using a virtual pen. Pen blocks are colored mint green. There are pen blocks that let you enable and disable drawing, set color and pen size, and apply shading. Table 3.4 outlines all of the code blocks that fit into this category.

Table 3.4. Pen Blocks
BlockMonitorDescription
NoErases or clears away anything drawn by the pen or stamped from the stage.
NoPlaces the pen in a down position, allowing drawing operations to occur as the pen is moved around the stage.
NoDisables drawing operations by lifting the pen.
NoSpecifies the color to be used when drawing.
NoChanges the color used when drawing by a specified amount.
NoSpecifies the color to be used when drawing based on a numeric range in which 0 is red (at the low end of the spectrum) and 100 equals blue (at the high end of the spectrum).
NoModifies the shading used when drawing by a specified amount.
NoSpecifies the shade to be used when drawing based on a numeric range in which 0 is the darkest possible shading and 100 represents the maximum possible amount of light.
NoModifies the thickness of the pen based on a numeric increment.
NoSpecifies the thickness or width of the pen used when drawing.
NoDraws or stamps the image of a sprite onto the stage.

You will learn more about pen blocks in Chapter 12, “Drawing Lines and Shapes.”

Looping, Conditional Logic, and Event Programming

Control blocks automate the execution of scripts, pause script execution, and send messages to other sprites, allowing sprites to synchronize their execution. There are also control blocks that let you set up loops to repeatedly execute collections of code blocks as well as control blocks that let you conditionally execute other code blocks based on whether or not a test condition evaluates as true. Control blocks are colored gold. Table 3.5 outlines all of the code blocks that fit into this category.

Table 3.5. Scratch Pen Blocks
BlockMonitorDescription
NoExecutes the script to which it has been attached whenever the IDE’s green flag button is pressed.
NoExecutes the script to which it has been attached whenever a specified keyboard key is pressed.
NoExecutes the script to which it has been attached whenever the user clicks on the sprite to which the script belongs.
NoPauses script execution for a specified number of seconds, after which the script resumes its execution.
NoRepeatedly executes all of the code blocks embedded inside it.
NoRepeats the execution of all the code blocks embedded inside it a specified number of times.
NoSpecifies a broadcast message to all sprites without pausing script execution.
NoSends a broadcast message to all sprites to trigger a predefined action and then pauses script execution, waiting until all sprites have completed their assigned action before allowing the script in which the block resides to continue executing.
NoExecutes the scripts to which it has been attached when a specified broadcast message is received.
NoRepeatedly executes all of the code blocks embedded within the control for as long as the specified condition evaluates as true.
NoExecutes all of the code blocks embedded within the control if the specified condition evaluates as true.
NoExecutes all of the code blocks embedded in the top half of the control (between the If an Else) if the specified condition evaluates as true and executes all of the code blocks embedded in the bottom half of the control (after Else) if the condition evaluates as being false.
NoPauses script execution until a specified condition becomes true.
NoRepeats all of the code blocks embedded inside it for as long as a tested condition evaluates as true.
NoHalts a script’s execution.
NoHalts the execution of all scripts for all sprites in the application.

You will learn more about control blocks in Chapter 9.

Sensing Sprite Location and Environmental Input

Sensing blocks determine the location of the mouse-pointer, its distance from other sprites, and whether a sprite is touching another sprite. Sensing blocks are colored sky blue. There are sensing blocks that can be used to interact with Scratch boards, allowing applications to detect when the sensor board’s buttons or slider are being pressed. Table 3.6 outlines all of the code blocks that fit into this category.

Table 3.6. Scratch Pen Blocks
BlockMonitorDescription
NoRetrieves the location of the mouse-pointer on the X-axis.
NoRetrieves the location of the mouse-pointer on the Y-axis.
NoRetrieves a Boolean value of true or false, depending on whether a mouse button is pressed.
NoRetrieves a Boolean value of true or false, depending on whether a specified key is pressed.
NoRetrieves a Boolean value of true or false, depending on whether the sprite is touching a specified sprite, edge, or mouse-pointer as selected from the block’s pull-down menu.
NoRetrieves a Boolean value of true of false, depending on whether the sprite is touching a specified color.
NoRetrieves a Boolean value of true of false, depending on whether the first specified color inside the sprite is touching the second specified color on the background or on another sprite.
NoRetrieves a numeric value representing a sprite’s distance from another sprite or from the mouse-pointer.
NoResets the timer back to its default value of zero.
YesRetrieves a numeric value representing the number of seconds that the timer has run.
NoRetrieves the property value (x position, y position, direction, customer #, and size of volume) for the background of a specified sprite.
YesRetrieves a numeric value, from 1 to 100, representing the volume of the computer’s microphone.
YesRetrieves a Boolean value of true or false when a sound value of 30 or greater is detected through the computer’s microphone.
YesRetrieves the value being reported by one of the sensors on a Scratch board.
YesRetrieves a Boolean value of true or false, depending on whether a specified sensor is being pressed.

Note

A Scratch board is a special piece of hardware that you can purchase from the Scratch website and attach to your computer. Once it is attached, you can use a sensor board to collect and process environment- and user-provided input. You will learn how to programmatically interact with and control Scratch boards in Chapter 14, “Collecting External Input Using a Scratch Sensor Board.”


You will learn more about sensing blocks in Chapter 6, “Sensing Sprite Position and Controlling Environmental Settings.”

Working with Numbers

Numbers blocks perform arithmetic operations, generate random numbers, and compare numeric values to determine their relationship to one another. Numbers blocks are green. There are numbers blocks that can be used to round numeric values and to execute a host of mathematical functions like determining absolute value or square root of a number. Table 3.7 outlines all of the code blocks that fit into this category.

Table 3.7. Scratch Pen Blocks
BlockMonitorDescription
NoAdds two numbers together and generates a result.
NoSubtracts one number from another and returns the result.
NoMultiplies two numbers together and generates a result.
NoDivides one number into another and returns the result.
NoGenerates a random number within the specified range.
NoReturns a Boolean value of true or false, depending on whether one number is less than another.
NoReturns a Boolean value of true or false, depending on whether one number is equal to another.
NoReturns a Boolean value of true or false, depending on whether one number is greater than another.
NoReturns a Boolean value of true or false, depending on whether two separately evaluated conditions are both true.
NoReturns a Boolean value of true or false, depending on whether either of two separately evaluated conditions is true.
NoReverses the Boolean value from true to false or false to true.
NoRetrieves the remainder portion of a division operation between two numbers.
NoReturns the nearest integer value for a specified number.
NoReturns the result of the selected function (abs, sqrt, sin, cos, tan, asin, acos, atan, Ln, log, E^, and 10^) when applied to the specified number.

You will learn more about number blocks in Chapter 8, “Doing a Little Math.”

Storing and Retrieving Data

Variables blocks store and retrieve numeric values in computer memory. You will need to use variables to store data as your application executes. For example, if you create a game that challenges the player to try and guess a randomly generated number, you will need to use a variable to store and refer back to this number.

Variables can be used in conjunction with conditional programming logic to control the execution of other code blocks. Variables can also be used to control the repeated execution of code blocks embedded within code block loops. Variables blocks are colored orange. You can create and name custom variables blocks and assign them a starting value. You can also modify their values during script execution. Other code blocks can retrieve variable values and use them as input. Table 3.8 outlines all of the code blocks that fit into this category.

Table 3.8. Scratch Pen Blocks
BlockMonitorDescription
NoModifies the value assigned to a numeric value stored in a variable by the specified amount.
NoAssigns a value to a numeric variable.
YesRetrieves the value assigned to a variable.

You will learn more about variables blocks in Chapter 7.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.25.183