Skip to content
Related Articles
Open in App
Not now

Related Articles

Basics of Scratch Programming

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 18 Nov, 2022
Improve Article
Save Article

Scratch is a programming language. Programming language is meant that a means of communicating with the computer, so as to give some instructions for it to perform. Programming in Scratch is very easy, including animation and games. It is a very useful tool for young kids or creators to learn and implement coding logic. It was developed by MIT’s Media Lab and it is free and can be used online on its, website, or it can be downloaded to use offline. It is available for operating systems like Windows, iOS, ChromeOS, Android 6.0+, etc. In this article, we will discuss the basics of Scratch.

Script

In Scratch, a script is a set of instructions that are used to create a Scratch program. Or we can say that it is a stack of blocks that are connected with each other and perform the specified tasks. Scripts are used to interact with sprites and tell them what to do or say. We can create a script in the script area. Here, we drag the blocks from the block palette and assemble them to create scripts. 

Script

Sprite

There are objects and characters that could be added to a program to perform actions based on code written in scripts in a project using blocks, these objects and characters are known as Sprite. You can add a prebuilt sprite or create a new sprite as per your requirement. You can find the option to add the sprite in the right bottom corner, second menu from the right corner. There are many free sprites already available in the store, you can choose any of them or can paint a new sprite, or upload any other sprite. Below are some of the preloaded sprites from the scratch,

 Scratch-Sprite

Some Sprites of Scratch 

Tempo

If you want to attach any instrumental blocks or beats to your scratch project then you need to determine how fast your note has to play. Whether you want to play the same beat for 60 seconds you want to play 3-4 beats for some time period. This control of the speed of instrumental beats in Scratch is known as Tempo.

Tempo

Events

Events in Computer Science refer to the trigger, which makes anything happen when any button is clicked or any action has happened. In Scratch, events are represented by Yellow color blocks, which include when the flag is clicked, when the sprite is clicked, when the key is pressed, etc.

Events

Backdrops

When you program something in Scratch, you have full freedom to use and change the background, before or during the program. These background effects are known as Backdrops.

Backdrops

Coding Blocks

Coding blocks are some pre-defined or pre-written blocks of code that make writing statements of code very simple in Scratch. You can use any coding blocks by simply dragging and dropping as per your requirements. You may also create your custom block if you want. Below are a few of the coding blocks explained in brief. Besides, there are various other coding blocks available, and also you and create your blocks too. 

  • Motion: These are used to move a sprite back and forth or in any direction or rotate them.
  • Looks: These are used to change the look of the sprite or replace them with some other sprite of the same category.
  • Sounds: Tempo or Sounds are used to control the sound flow in the program.
  • Events: Events handle trigger calls.
  • Controls: Conditional operators and loops are all in this category.
  • Sensing: Sensing controls how to react whenever the mouse pointer hits the playground and/or touches the sprite or by the motion of the mouse.
  • Operators: These are for the control and flow of arithmetic operations in the program.
  • Variables: You can declare the variables, in your program using these blocks.
  • My Blocks: You can create your custom blocks from here. 

Coding-blocks

Loops 

Loops in Scratch or any programming language help you execute the same line of code with or without different values for ‘n’ a number of times. You can either set the number of times or set a condition to end the loop. Scratch supports the following loops:

  • repeat: This block is used to iterate the given set of instructions ‘n’ a number of times. Here, the value of n is a positive number.
  • forever: This block is used to execute the given set of instructions infinitely.
  • repeat until: This block is used to iterate the given set of instructions until the given condition is not satisfied. 

Loops

Conditions

Conditions in Scratch are implemented using Control blocks. You can use control blocks to check for a condition and based on if the condition is true or false, the required code/script can be executed. Two of the most popular control blocks are:

  • if-then: In this block, if the given condition is true the code/script present inside this block will execute. Otherwise, the code/script present inside this block will be ignored.
  • if-then-else: In this block, if the given condition is true the code/script present inside this block will execute. Otherwise, the code/script present inside the else block will execute.

Projects

Any creation in Scratch such as code for a game, story, or animation is termed as a project in Scratch. You can create a project by using the Scratch editor. Once a project has been created it can be shared with other Scratch programmers (called Scratchers). As of Sep, 22 there are over 100 million shared projects in Scratch. 

Any scratches can use the code of a shared project and create another project through it. This process is called “Remixing”. As part of the community guidelines, you should acknowledge the creator of the original project whenever you are remixing their code. 

Scratch Project Example

Below is the implementation of a simple program:

Here we have made a girl walk along the beachside. She will walk a few steps and then say “Hello”. Let’s see how we have implemented this.

  1. First, you have to select a suitable backdrop for your project. Here I have used the “Beach Malibu” backdrop.
  2. Select the sprite you want to work with. Here I have used the “Avery walking” sprite.
  3. Follow the following script:

Scratch-project-example

Working of Code

  • The first event is when the flag is clicked, it is for starting the program.
  • The second block of code makes the sprite located in the initial position that is x is -164 and y is -69.
  • Then we placed a loop to repeat moving by changing the costume 20 times.
  • After completing the loop the sprite will say hello for one second.

Output:

Output

Scratch program running demo 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!