Script
Script
Scratch is visual programming to create your own games, stories, and animations.
The set of instructions that is used to program in Scratch is called a script.
A script is a stack or collection of blocks that connect with one another. The blocks
of instructions are nicely ordered to perform a specific task, as they determine to
interact sprites. It’s a good way to add comments in the script to define what is
being done. In Scratch, a sprite is an actor or main character of the program or a
graphic element that performs all the activities that are given in the script.
Use of Scratch Script:
• To create a Scratch script, just simply drag blocks out of the block palette
and assemble them.
• To disassemble the blocks from the script, drag them apart from the
scripting area.
• To remove a script from your program, select the script and press delete.
• To execute a single script just click on it.
Structure of Scratch Script:
• Starting a script such as a click the green flag to start.
• Add to the end of a script.
• Ending of a script
• Essential to fit inside other blocks.
• Contain other blocks.
Script Area:
Script area is present on the right side of the programming palette, here the scripts
are assembled. From the programming palette or block palette, blocks are dragged
to the script area to store and execute in a project. Or you can stack them together to
create a script. When you right-click on the script area you will get the following
options: Undo, Redo, Clean up blocks, Add comments, and Delete blocks.
Script Fragment:
In a Scratch, a script fragment is known as an incomplete script, which means a
script that has no hat block. in normal execution, script fragments will not run
because there is not a hat block available to start the code. They are generally used
to create thumbnails because it has the ability to show sprite that is not visible while
normal execution of the program. They are generally stored in the backpack(it is a
special feature that stores user’s projects) and easily appear on a hat to run the
code. Every block present in the editor is the script fragment.
Example 1 – Moving Logo
In this example, we will create a scratch program to move the logo 30 degrees
clockwise.
Procedure:
Step 1: Open scratch editor.
Step 2: Drag the “when space key pressed” block from the event block on the script.
Step 3: Now drag the “forever” block from the event block and place this block under
the “when space key pressed”.
Step 4: Now drag the “wait” block from the event block and place this block under the
“forever” block.
Step 5: Now drag and place “turn degrees” block from the motion block under the
“wait” block. Now change the value from 15 to 30 degrees clockwise.
Step 6: Now run the script.
Below is the execution of the above procedure: