Summary

This document provides an overview of different types of blocks used in block-based programming, particularly focusing on examples in Scratch. It describes different block types and their functionalities.

Full Transcript

ITJH2401 TYPES OF BLOCKS There are different types of blocks in block programming, but the mainly used ones are motion, loop or control, visual, event, and sound blocks. You can see in the photo different sections in Scratch where you can do block programmi...

ITJH2401 TYPES OF BLOCKS There are different types of blocks in block programming, but the mainly used ones are motion, loop or control, visual, event, and sound blocks. You can see in the photo different sections in Scratch where you can do block programming. 04 Handout 1 *Property of STI Page 1 of 12 ITJH2401 Here is the block type section where you can choose what group of blocks you will use. Depending on what type of program you will do, you can freely choose from different types of blocks. You can also just scroll down in the next section depending on your preference of navigation. This is the work area section where you put the blocks you are going to use. You drag-and-drop the block from the earlier section into this section so that your backdrop or sprite will have logic that will work upon pressing the start or green flag. 04 Handout 1 *Property of STI Page 2 of 12 ITJH2401 And finally, the stage where you can see the output, sprites, and backdrops you are using. This is also where the x and y coordinates of sprites, sizes, and directions are shown. Motion Block Motion blocks are an essential part of programming in block programming, they allow you to control the movement of your sprites. You can use them to create games, animations, and other interactive programs. Block Description The block moves its sprite forward the specified number of steps in the direction it is facing. A step is equal to one pixel length. The blocks turn their sprite the specified number of degrees to the right clockwise. The blocks turn their sprite the specified number of degrees to the left counterclockwise. 04 Handout 1 *Property of STI Page 3 of 12 ITJH2401 This block allows to direct and rotate the sprite in the determined direction. The block points its sprite towards the mouse-pointer or another sprite depending on its costume’s center. This changes the sprite’s direction and rotates the sprite. This block positions the sprite at the position defined by the x- coordinate and the y-coordinate on the stage. This block moves the sprite to the location of the mouse pointer, another sprite, or to a random position. This block drags the sprite to the position defined by the x- coordinate and the y-coordinate on the stage. This block drags the sprite to a random position on the stage. The block moves its sprite costume center’s X position by the specified amount. The block changes the selected sprite’s X position to a specified value. The block moves its sprite’s Y position by the specified amount. 04 Handout 1 *Property of STI Page 4 of 12 ITJH2401 This block changes the y-coordinate of the sprite by the specified value. This block rotates the sprite in the opposite direction when it hits the edge of the stage. The block changes the Rotation Style of the sprite in-project. Regardless of the style, the variable direction will still change. This block returns the x-coordinate of the sprite’s position. This block returns the y-coordinate of the sprite’s position. The block holds its sprite’s direction, measured in degrees. Loop Block A key component of coding, loop blocks determine when and how often other blocks get activated. They allow you to create more complex and interactive programs. Block Description The block suspends its script for the specified number of seconds. The expectation can also be a decimal number. 04 Handout 1 *Property of STI Page 5 of 12 ITJH2401 The blocks inside this block will loop based on the specified number, before allowing the script to continue. If a decimal is inserted, the number is rounded. Blocks held inside this block will be in a loop. Just like the Repeat () block and the Repeat Until () block, except the loop never ends until the stop sign is clicked. If its Boolean condition is true, the blocks inside it will run. If the condition is false, the blocks inside the block will be ignored. The condition is only checked once. The block will check its Boolean condition: if the condition is true, the code contained in the first space will be activated, then the script will continue. If the condition is false, the code inside the second space will activate. The block suspends its script until the specified Boolean condition is true. 04 Handout 1 *Property of STI Page 6 of 12 ITJH2401 The blocks within this block will loop until the specified Boolean statement is true, in which case the code under the block will execute. Depending on the option chosen in the drop-down, it is either all, this script, or other scripts in sprite. This block activates in a clone when created. This block creates a clone of the sprite in the argument. It can also clone the sprite it is running in, creating clones of clones, recursively when put under “When I start as a clone” block. This block deletes the clone it is running in. This block is the only way besides clicking the green flag or stop sign to remove clones. Event Block Event blocks allow you to create interactive programs that respond to user input and other events. These are actions that trigger code in your program or game. Event blocks start and stop your code from running based on specific events. Block Description Scripts that carry this block will activate once the green flag is clicked. 04 Handout 1 *Property of STI Page 7 of 12 ITJH2401 Scripts placed under this block will activate when the specified key is pressed. Scripts that carry the block will activate once its sprite or sprite clone is clicked. Contrary to its final name, the block will also execute the clone’s script when it is clicked. Scripts that carry this block will be triggered once the specified background has been toggled on the stage. It starts the script below it when a value (chosen by the drop-down menu) is greater than another value (entered by the number input). The block activates its script when the specified broadcast has been sent by a calling script. The block sends a broadcast throughout the Scratch program. This broadcast block allows scripts to send broadcasts without any waits in its script. Broadcasts are a great way to communicate sprites and scripts. The block sends a broadcast throughout the Scratch project. All scripts that are stopped with the When I receive () block and are set to broadcast will activate. Sound Block In block programming, sound blocks are blocks of code that allow you to add sound to your programs. You can use sound blocks to play sound effects, music, and other audio in your programs. 04 Handout 1 *Property of STI Page 8 of 12 ITJH2401 Block Description The block will play the specified sound, pausing its script until the sound has finished playing. The block plays the specified sound and continues executing the script. The block will stop any sounds currently being played on all sprites and the stage. It changes the sound effect chosen by the amount. This will be changed for all sounds played in the sprite. It sets the specified sound effect for all sounds played in that sprite to the specified amount. It clears any sound effects currently in place via the sound effect blocks, which are the pitch block and the pan left/right block. The block changes the volume of a sprite. This only affects the sprite or stage that the block is in. The block sets the volume of a sprite. This only affects the sprite or stage that the block is in. 04 Handout 1 *Property of STI Page 9 of 12 ITJH2401 The block holds a Sprite’s, clone’s, or the Stage’s volume. Visual Block Visual blocks allow you to change the appearance of your sprites. You can use them to create animations, change the way your sprites look, and add dialogue to your programs. Block Description The block gives its sprite a speech bubble with the specified text. The speech bubble remains until another speech or thought block is activated or the stop sign is pressed. The block displays a speech bubble with the text specified for the sprite executing it, which appears on the screen for the specified number of seconds. The block gives its sprite a thought bubble with the specified text, which remains for a specified number of seconds. The block gives its sprite a thought bubble with the specified text. The thought bubble stays until another speech or thought block is activated or the stop sign is pressed. The block changes its sprite’s costume to a specified one. This block is used whenever a sprite must switch to a specific costume. The block changes its sprite’s costume to the next one in the costume pane, but if the current costume is last in the list, the block will loop to the first one. 04 Handout 1 *Property of STI Page 10 of 12 ITJH2401 The block changes the scene background to the one specified. The block changes the background to the next in the list of backgrounds, but if the current background is last in the list, the block will loop to the first. The block changes its sprite’s size by the specified number. The default sprite size is 100. Size values below that percentage are for smaller sprites, and size values above it are for enlarged sprites. The block sets its sprite size to the specified value. The default sprite size is 100%. Anything below that will decrease the size of the sprite on the Stage, and anything above will increase the size of the sprite on the stage. The block changes the specified effect on its sprite by the specified amount. The block sets the specified effect on its sprite to the specified amount. This block resets the graphic effects. If the block sprite is hidden, it will display the sprite. If the sprite is already displayed, nothing will change. 04 Handout 1 *Property of STI Page 11 of 12 ITJH2401 If the block sprite is displayed, it will hide the sprite. If the sprite is already hidden, nothing happens. The block makes a sprite go to the very backmost or frontmost layer. A sprite at the backmost layer will be covered by any sprites in front of it while a sprite at the frontmost layer cannot be covered by another sprite. The block moves its sprite forward or backward a given number of layers. Moving a sprite forward causes it to appear in front of other sprites, and moving it backwards causes it to appear behind others. This block is only available in sprites. It returns the costume number or the costume’s name. It returns the backdrop number or the backdrop’s name. The block holds its sprite’s size. References: Gagniuc, P. A. (2023). An introduction to programming languages: Simultaneous learning in multiple coding environments. Springer. Hour of Code - What will you create? (n.d.). Code.org. https://hourofcode.com/us Perugini, S. (2021). Programming Languages: Concepts and implementation. Jones & Bartlett Learning. Scratch - imagine, program, share. (n.d.). https://scratch.mit.edu/ Wassberg, J. (2020). Computer programming for absolute beginners: Learn essential computer science concepts and coding techniques to kick-start your programming career. Packt Publishing Ltd. 04 Handout 1 *Property of STI Page 12 of 12

Use Quizgecko on...
Browser
Browser