Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Script in Scratch Programming

  • Difficulty Level : Medium
  • Last Updated : 21 Jul, 2021

Scratch is an event-driven programming tool developed by the Lifelong Kindergarten group at MIT in the media lab to create your own games, visual programs, interactive stories using building blocks. To create a program in Scratch we do not need to write code to perform operations. In Scratch, the operation is performed just by drag and drop, similar to visual basic. It is a very good tool to start your programming. 

What is Scratch 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. It 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.  

Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the  Demo Class for First Step to Coding Coursespecifically designed for students of class 8 to 12. 

The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.

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:



Example 2 – Moving cat using arrows with sound

In this example, we will create a Scratch program to better understand the Scratch script. Along with an example, the live project link will be attached and also used through a webpage using an iframe. This program is designed in Scratch with some simple scripts. We will understand every aspect of this program.

Step 1: Open scratch editor.

Step 2: First, we used an event, i.e., “When green flag” from the events section. It declares that our program will be executed when we click on the green flag (execution button).

Step 3: Drag a forever loop from the controls section. It is similar to the for loop like other programming languages. The iteration of the program is done by this forever loop.

Step 4: In the next step, we take four conditions according to the arrow to control our program. It defines the sprite (cat) will be moved-in a specified direction with a meow sound.

Step 5: Now run the script.

Below is the execution of the above procedure:

My Personal Notes arrow_drop_up
Recommended Articles
Page :