0% found this document useful (0 votes)
1K views

Introduction To Scratch

The document provides an introduction and overview of the visual programming language Scratch. It discusses that Scratch can be used to create interactive games and animations, has a large online community for sharing projects, and aims to help children think creatively and solve problems. It also provides step-by-step instructions for creating a Scratch account and starting a new project.

Uploaded by

Gary Ching
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Introduction To Scratch

The document provides an introduction and overview of the visual programming language Scratch. It discusses that Scratch can be used to create interactive games and animations, has a large online community for sharing projects, and aims to help children think creatively and solve problems. It also provides step-by-step instructions for creating a Scratch account and starting a new project.

Uploaded by

Gary Ching
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Chapter 1: Introduction to Scratch

Scratch is a block-based visual programming language that can be used to make


interactive games and animations. It has a huge online community where you can
share, discuss and view scratch programs. The objective behind the development of
Scratch is to help children(mostly) to think creatively, work collaboratively and solve
problems systematically.

Users can directly create projects on the official website using a block-like interface.
Create Your Scratch Account:

You will need a Scratch account to create, save, and share your Scratch projects. The
steps below will walk you through creating a new account and setting up your profile.

● Open a web browser and navigate to the Scratch official website.


● On the Homepage, click on “Join Scratch” at the top on the right of the page.

● Fill in your preferred username and password. Then click on Next.


At this stage, you have successfully created an account on Scratch.
Create a New Project on Scratch:

● Open a web browser and navigate to the Scratch official website.


● Sign in to your account.
● Click on the “Create” tab located at the top left of the browser to start a new
project.

● Time to explore! Try clicking on different parts of the Scratch interface to see
what happens.
● Play with different Scratch blocks! Drag and drop Scratch blocks into the
scripting area. Experiment by clicking on each block to see what they do or try
snapping blocks together
Chapter 2: Basics of Scratch Programming

Scratch is a programming language. By programming language, it is meant that a


means of communicating with the computer, so as to give some instructions to 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.
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 on the right bottom corner, second
menu from the right corner. There are many free sprites already available in 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,
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. Like whether you want to play the
same beat for 60 seconds to 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.
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 flag clicked, when sprite clicked, when key
pressed, etc.
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.
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 others 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.

Loops

Loops in Scratch or any programming language help you execute the same line of code
with or without different values for ‘n’ 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’ 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.
● 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.
● repeat until: This block is used to iterate the given set of instructions until the
given condition is not satisfied.
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:
Working of the 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 have 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:
Chapter 3: Script in Scratch Programming

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.

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:
Chapter 4: What is Conditional Programming in Scratch?

Scratch is a high-level visual programming language tool that interacts with users
through diagrams and blocks that have the basics of a program inbuilt in it. Scratch is
used to make interactive programs especially for kids using the block kind of interfaces
so that they can easily learn languages and it is free to use. In this article, we will learn
about coordinates and conditionals.

Coordinates System

In Scratch, the coordinate system is used to locate the sprite(actor if the scene) on the
screen or we can say that the coordinate system is a mathematical grid with infinite
values. It is a two-dimensional cartesian coordinate system and is used to allocate a
point/object or to extract the position of the object/point.

Position: Coordinate system has two coordinates, i.e., X position and Y position to find
the position of the sprite on the screen. Here, X position denotes the horizontal location
of the sprite and the Y position denotes the vertical location of the sprite. The X position
can range from 240 to -240, where 240 is the rightmost side of the stage or screen and
-240 is the leftmost, and the Y position ranges from 180 to -180, where 180 is the
topmost side and -180 is the bottom-most side. and coordinates can be written as (X,
Y). For example, (3, 4) is the coordinate of a sprite on the stage.

To change the backdrop of the scratch to a xy-grid. In the bottom right corner of the
screen, click on the “backdrop” option to choose the x-y coordinate system as
background.
There will be numerous lists of backdrops that scratch offers as shown below:
Now, choose the “xy grid” backdrop and you will observe that the background of sprite
changes to xy grid. This xy grid gives an exact idea of the minimum, maximum, and
centre values of the x and y coordinate. When the sprite is moved from one place to
another, the corresponding x, y coordinate is also shown simultaneously. This is
depicted in the above gif.

The X position and Y position of a sprite can be determined, set, and changed by using
the motion block. Below are the ways in which the coordinate of a sprite can be
modified.
Conditionals in scratch

Conditional statements have conditions and the programs flow based on the true or
false value of the condition. They are found in the control programming blocks as shown
below.
Here, if() then and if() then else are the conditional blocks.

1. if() then block

It is a control block. This block works on the condition’s value. If the condition is true,
then the set of code is executed else nothing happens. Here, the condition is only
checked once, and if the condition is changed to false while the script is running, then
the script will keep running until it is finished. It is just like the if-else statement in
languages like Java, Python, etc. Let’s understand this concept by making a small
project. Let us understand the working of the wait block with the help of a simple project.
In this project, if the user types “a”, then the sprite must glide for 1 second.

Procedure:
Step 1: Click on event block and choose 1st control block denoting start of the
program(drag it to center).

Step 2: Click on control block and drag if then block below the above step.

Step 3: Go to the sensing block and drag key space pressed and place it inside the
condition of if-then block and change “space” to “a”

Step 4: Go to motion block and drag glide 1 sec to random position inside if-then block.

Step 5: Now, run the program.

Below is the implementation of the above procedure.


2. if-then-else

It is a control block. This block is an extension of the if-then value. If a condition is true,
then a set of lines gets executed. If a condition is false, then else part is executed. Let
us understand the working of the wait block with the help of a simple project. In this
project, if the user types “a”, then the sprite must glide for 1 second, else the sprite must
say “hello”.

Procedure:

Step 1: Click on event block and choose 1st control block denoting the start of the
program(drag it to center).

Step 2: Click on the control block and drag if then block below the above step.
Step 3: Go to the sensing block and drag key space pressed and place it inside the
condition of if then block, change “space” to “a”

Step 4: Go to motion block and drag glide 1 sec to a random position, inside the if then
block.

Step 5: Go to looks block and drag say hello block inside else part.

Step 6: Now run the program

Below is the implementation of the procedure:


Chapter 5: What is Iteration in Scratch Programming?

Scratch is a high-level visual programming language tool that interacts with users
through diagrams and blocks that have the basics of a program inbuilt in it. Scratch is
used to make interactive programs especially for kids using the block kind of interfaces
so that they can easily learn languages and it is free to use. In this article, we will
discuss the iteration block present in scratch.

Scratch iteration block

Iteration is the concept that allows the repetition of commands or a set of lines. It is also
known as a loop in the computer programming language. When the code
executes(repeated) one time then this repetition is known as one iteration. The Iteration
control block basically reduces the number of similar tasks to be performed by grouping
the similar tasks in one block. In Scratch, the control block contains iteration tools as
shown in the below image:
Now, let’s understand each iteration block in detail:

1. repeat (number n) block

It is a control block. This iteration block iterates the given set of commands ‘n’ number
of times. The number n can be any positive integer. Here, n is the stopping condition of
the iteration block. If the value of n is infinite then the loop runs forever, if the value n is
a non-positive number then this loop will not run, and if the value of n is a decimal
number then the number is round up. Let us understand the working of the repeat block
with the help of a simple project:

Procedure:
Step 1: Click on event block and choose 1st control block denoting the start of the
program(drag it to center).

Step 2: Click on add extension and choose pen block for drawing square.

Step 3: Place pen down block below the event block.

Step 4: Now drag the repeat block from the control block and place it down of pen down
block. Change the number from 10 to 4.

Step 5: Click on motion block and drag move block and place it inside repeat block.
Change the number from 10 to 50.

Step 6: Click on the turn block and place it below the move block inside the repeat
block. Change the number from 15 to 90.

Step 7: Now run the program.


Below is the implementation of the procedure:

2. nested repeat block


A nested repeat block is created by placing a repeat block inside another repeat block.
Here, two integer numbers will be used for the stopping condition. Let’s understand this
by making a small project:

Procedure:

Step 1: Click on the event block and choose the 1st control block denoting the start of
the program(drag it to center).

Step 2: Click on add extension and choose pen block for drawing a square.

Step 3: Place pen down block below the event block.

Step 4: Now drag repeat block from control block and place it down to the pen down
block. Now change the number from 10 to 2.

Step 5: Now, again drag the repeat block from the control block and place it inside the
first repeat block. Now, change the number from 10 to 2.

Step 6: Click on the motion block and drag the move block and place it inside the
repeat block. Now, change the number from 10 to 50.

Step 7: Click on the turn block and place it below the move block inside the nested
repeat block. Now, change the number from 15 to 90.
Step 8: Now run the program.

Below is the implementation of the procedure:

3. forever block
It is a control block. This iteration block executes a particular set of commands infinitely.
There is no stopping condition present in forever block. This kind of block is used to
make patterns that are infinite in nature. For example, the square spiral. Let us
understand the working of the forever block with the help of a simple project(i.e. square
spiral):

Procedure:

Step 1: Click on event block and choose 1st control block denoting the start of the
program(drag it to center).

Step 2: Click on add extension and choose pen block for drawing square spiral.

Step 3: Place pen down the block below the event block.

Step 4: Go to variable block and drag “set my variable to 80”.

Step 5: Drag the forever block from the control block and place it down of pen down
block.

Step 6: Click on motion block and drag move block and place it inside the repeat block.
Now change the number to “my variable”.

Step 7: Click on turn block(inside motion block) and place it below the move block
inside repeat block. Now, change the number from 15 to 90.
Step 8: Go to variable block and drag “change my variable by 5”.

Step 9: Now run the program.

Below is the implementation of the procedure:


4. repeat until block

It is a control block. This iteration block executes a particular set of commands until a
particular condition is not satisfied. The condition inserted in until is the stopping
condition of the loop. This block is used when the stopping condition is known
beforehand. Let us understand the working of the forever block with the help of a simple
project. In this project, we draw a hexagon and the stopping condition of the hexagon
would be 6.

Procedure:

Step 1: Click on the event block and choose the 1st control block denoting the start of
the program(drag it to center).

Step 2: Click on add extension and choose pen block for drawing a square spiral.

Step 3: Place pen down block below the event block.

Step 4: Go to variable block and drag “set my variable to 0”.

Step 5: Drag repeat until block from control block and place it down of pen down the
block.

Step 6: Go to operator block and drag O = O block and fill in the left blank with “my
variable” and right blank with 6. Fix this in until blank.
Step 7: Click on motion block and drag move block and place it inside repeat until
block. Now change the number to 50

Step 8: Click on turn block(inside motion block) and place it below the move block
inside repeat until block. Now change the number from 15 to 60.

Step 9: Go to variable block and drag “change my variable by 1”.

Step 10: Now run the program.

Below is the implementation of the procedure:


5. nested repeat until block

A nested repeat until block is created by placing a repeat until block is placed inside
another repeat until block. Here, two conditions will be used for stopping conditions.
Let’s understand this by making a small project.

Procedure:

Step 1: Click on event block and choose 1st control block denoting start of the
program(drag it to center).

Step 2: Click on add extension and choose pen block for drawing square.

Step 3: Place pen down block below the event block.


Step 4: Go to variable block and click on “make a variable”, name it a, drag “set a to 0”.

Step 5: Drag repeat until block from control block and insert it in another repeat until
block.

Step 6: Go to operator block and drag O=O block and fill the left blank with “a” and right
blank with 3. Fix this in until blank.

Step 7: Go to the variable block and drag “set my variable to 0” and place it inside
repeat until block.

Step 8: Go to operator block and drag O=O block and fill left blank with “my variable”
and right blank with 3. Fix this in the second repeat until blank.

Step 9: Click on motion block and drag move block and place it inside repeat block.
Now, change the number from 10 to 50.

Step 10: Go to variable block and drag “change my variable by 1”.

Step 11: Click on the turn block and place it below the move block inside the repeat
block. Now, change the number from 15 to 60.

Step 12: Outside the inner repeat block, go to the variable block and drag “change a by
1”.
Step 13: Now run the program.

Below is the implementation of the procedure:


Chapter 6: Ask(), Wait() and Answer() Block in Scratch Programming

Scratch is a high level visual programming language tool that interacts with users
through diagrams and blocks that have the basics of a program inbuilt in it. Scratch is
used to make interactive programs especially for kids using the block kind of interfaces
so that they can easily learn languages and it is free to use. In scratch, ask() and wait,
the wait blocks are the block that senses the input and shows the output as per the
input typed (i.e., the answer block).

ask() and wait block

The ask() and wait block is sensing and a stack block. It is a single block that first asks
the question to the user and then waits for the input from the user. Or in other words, in
ask() and wait block, the ask() block makes any sprite (actor of the scene) to display
questions. The programmer can change the question to whatever they wish to ask the
user. Simultaneously, an input field appears on the bottom of the screen where the user
can type the input or answer the question and the answer/input is stored in the answer
block. The answer block is always updated to the recent input. The wait block is to wait
for the input of the user. If the question is asked by the sprite then the question will
display in the bubble and if the question is asked by the stage or hidden sprite, then the
question will display above the input block. You can find ask() and wait block in the
sensing block.
Let us understand the working of the wait block with the help of a simple project. In this
project we make a sprite asking the name of the user.

Procedure:

Step 1: Go to the costumes section and choose any sprite of your choice.

Step 2: Click on event block and choose 1st control block denoting the start of the
program(drag it to center).

Step 3: Go to sensing block, and drag the ask() and wait block below the above step.
Step 4: Now, run the program.

Below is the implementation of the procedure:


answer block

It is a sensing and reporting block. The main purpose of the answer block is to store the
answer(that was typed by the user in the input field) and, if needed, it can also display it
on the screen. The answer block consists of the most recent input typed by the user and
erases any previous inputs typed by the user. You can find the answer block in the
sensing block.

Let us understand the working of the wait block with the help of a simple project. In this
project we make a sprite ask the user how much degree the sprite must turn and then
turn the sprite to that much degree.
Procedure

Step 1: Click on event block and choose 1st control block denoting start of the
program(drag it to center).

Step 2: Go to sensing block, and drag the ask and wait block below the above step,
change the question from “whats your name” to “how much degree the cat must move?”

Step 3: Go to motion block and select “turn O degree”

Step 4: Go to sensing block, drag the answer block and place it inside O of turn degree
block

Step 5: Now run the program


Below is the implementation of the procedure:

wait block

It is a control and stack block. As the name suggests, this block is used to wait for n
number of seconds, where n is any integer. It is the most commonly used block and is
generally used when a sprite must wait for another action or is used in the time-critical
programs. You can find a wait block in the control block.
Let us understand the working of the wait block with the help of a simple project. In this
project we make a sprite say “hello” after 2 seconds of the start of the program

Procedure

Step 1: Click on event block and choose 1st control block denoting the start of the
program(drag it to center)

Step 2: Go to control block and drag wait for 2 second below the above step

Step 3: Go to looks block and drag the “say hello” block below the wait block

Step 4: Now run the program


Below is the implementation of the procedure:
Variables in Scratch Programming

Scratch is a high-level visual programming language tool that interacts with users
through diagrams and blocks that have the basics of a program inbuilt in it. Scratch is
used to make interactive programs especially for kids using the block kind of interfaces
so that they can easily learn languages and it is free to use. In this article, we will
discuss the variables in scratch.

Variables

Variables in programming terminology are simply a container that can store some value.
We can simply think of a box which has a number in it. The number inside the box can
be increased or decreased using an increment or decrement operator as and when the
program requires.

Variables basically store a varying value in the memory. They are designed in such a
way that they can store only one value inside it and the value stored inside it may vary
from numerics to strings or boolean. Being able to hold this bit of information allows us
to reference and manipulate it at many different places in a program. This ability makes
variables incredibly useful. For example, 123, abc, true/false, etc.

Scratch contains the following variables blocks:


Here,

● Variable: This block is used to reports the value of a variable


● set variable to 0: This block sets a selected variable to a specified value.
● change variable by 1: This block changes the value of the selected variable.
● show variable: This block display the specified variable in the project player.
● hide variable: The block reverses the “show variable” block.
Types of variables

In scratch, there are three types of variables:

1. Global variable: It is the default variable. It means that it can be changed or


accessed from any sprite in the project or stage, regardless of which sprite it
was created on. Scratch allows the user or programmer to select a global
variable by showing an option ” choose for all sprites”, or “choose and for this
sprite only?”. If the user or programmer chooses “choose for all sprites”, then
that variable becomes global as it can be accessed by anyone whoever
needs it. All the global variables are stored in RAM and they are the default
for those files in which they are created.
2. Local variable: It is one that can only be changed or accessed from the
sprite on which it was created. No other sprite can access this variable.
Scratch allows the user or programmer to select a local variable by showing
an option ” choose for all sprites”, or “choose and for this sprite only?”. If the
user or programmer chooses “choose for this sprite only”, then that variable
becomes local and only the current sprite has the access to it.
3. Cloud variables: It is a variable that allows users to store variables on the
server of the scratch. Cloud variables have the cloud-like symbol in front of
the variable name and they update themselves very quickly. Starting from
Scratch 3.0, the cloud variable supports only numeric data and the size of the
data is only 256 characters. In a single Scratch project, you are allowed to
create 10 cloud variables.

How to make a variable?

In Scratch, you can create variables in two different ways:


1. Using build-in variable: Scratch has an inbuilt variable named “my variable”, so the
users can directly use that.

Here, you can also change the name of the variable. Also, if you want to display this
variable on the stage, then check the checkbox present on the left side of the “my
variable” block.

2. User-define variable: In case the user wishes to make his own variable, with a
different name, then click on the “make a variable” button in the variable palette. After
clicking the “make a variable block” a form will appear on the screen.
Now, fill in the name of the variable and the new variable is created as shown below.
After clicking ” OK”, the following image depicts that variable a has been created.
What is the use of variable in scratch?

Variables are of immense help to the programmers. Some of the uses of variables in
Scratch are listed below:

● The most common use is to store values.e.g., if a project requires an user to


input a name and then remember that name, the name is stored in a variable.
The name can be later retrieved.
● It helps in writing efficient and less time-consuming scripts. As a variable’s
value can change, variables are often used in blocks that contain a number.
Let’s understand the use of variables with two projects.

1. Without using variable

In this project, we move the script by 3 steps, increment the step subsequently, wait for
1 second, and repeat this 3 times.

Procedure

Step 1: Click on the event block and choose 1st control block denoting start of
program(drag it to center)

Step 2: Go to the motion block and drag “change x by 10” block and place it below the
above step and change 10 to 3

Step 3: Go to the control block and drag “wait for 1 sec” and place it below the above
block

Step 4: Go to the motion block and drag “change x by 10” block and place it below the
above step and change 10 to 4

Step 5: Goto control block and drag “wait for 1 sec” and place it below the above block

Step 6: Go to the motion block and drag “change x by 10” block and place it below the
above step and change 10 to 5
Step 7: Now run the program

Below is the implementation of the procedure:


2. With using variable

As we could see, the above code was cumbersome and time consuming. So, we can
make this code simple and fast using variables. Let’s see how.

Procedure:

Step 1: Click on the event block and choose 1st control block denoting start of
program(drag it to center).

Step 2: Go to the variable block and drag “set my variable to 0” below the above
step.change 0 to 2.

Step 3: Go to the control block and drag “repeat 10” below the above step.change 10 to
3.
Step 4: Go to the motion block and drag “change x by 10” block and place it below the
above step and change 10 to “my variable”.

Step 5: Go to the control block and drag “wait for 1 sec” and place it below the above
block.

Step 6: Go to the variable block and drag “change my variable by 1” below the above
step.

Step 7: Now, run the program.

Below is the implementation of the procedure:


We can see that the use of variables made the code efficient and contributed to a lesser
line of code. The readability of code also increased when variables were used in the
program.

How to rename the variable?

You can rename the variable the following the given steps:

Step 1: Right-click on the variable. You will get a list that contains two options “Rename
variable” and “Delete the “my variable” variable”.
Step 2: Now select the “Rename variable” option. After clicking on this option, a
dialogue appears on the screen.
Step 3: Now write the name of the variable and press “OK”.

How to delete the variable?

You can delete the variable the following the given steps:

Step 1: Right-click on the variable. You will get a list that contains two options “Rename
variable” and “Delete the “newvar” variable”.
Step 2: Now select the “Delete the “newvar” variable” option. And your selected variable
will be removed from the palette.

You might also like