VP - Enhancing Scratch Projects Lesson

Enhancing Scratch Projects

Additional code can be added to enhance your Scratch projects.  In this lesson, you will receive information on how to add code for loops, If-Then statements, and variables.

Loops

Loops can be used to animate sprites. The sprites in Scratch have costumes which indicate movement.  When you add code to loop the Scratch costumes, the program will execute with the sprite moving (animated).  The Control code includes several blocks of code that will allow you to repeat the same instruction without adding multiple blocks of the same code.  Note how the repeat block is used in the image below to animate the bear walking.  If the repeat 10 block of code had not been added, the programmer would have had to add 80 of the switch costume blocks to get the bear to repeat the costumes 10 times.  If you would like to see the bear walk, access the Scratch program and add the code as indicated below.

Word of caution! When using the forever loop, the instruction will be repeated forever or until the program ends. No block of code can be added under a forever loop because the program will never be able to complete an infinity of repetitions.



If-Then Statements

If-Then statements are used when there is a need for a decision to occur.  The image below reflects the anatomy of an If-Then statement. 

Anatomy of an If-Then Statement
If condition Then action
Decision needed The up arrow key is pressed If the condition is true, Then lets the computer know that something needs to be done. The color effect is changed by 25.

The image below that reflects a block of code reflects the If-Then example.

 

Variables

There are several Variables code options in Scratch.  One option permits the programmer to make a variable.  The Make a Variable option will allow you to create a variable and indicate if the variable is for all sprites or the current sprite.  The variable Score was created in the image below.  The variable will be used to keep score for a game.  Notice that the name of the sprite is added because I selected the option For this sprite only.

 

 

The additional Variable blocks of code can be used to change the value inside a variable when desired.

Click here Links to an external site. to access additional Scratch resources to assist you in enhancing your Scratch Project.

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION