⭐ 1.6 Sequential Execution of Instructions

View

A Sprite is a flat image representing a character or object in your program.  So far, sprite characters have stayed still.  In this section, you will learn how to move around a Sprite and let it talk.

A TALKING SPRITE

By placing blocks in the Script area, the Sprite will tell us his/her name.  First go to the Code section located at the top left of the Scratch home page. 

Go to the event folder.

Place the following block in the Script area:

This block is a ‘When’ command. This means that, once the Green flag above the Stage is clicked, the Sprite will follow the commands that are placed in the Script area.

  1. Go to the Looks section located in the Folders panel.
  2. Select the blocks twice that Say Hello for two seconds.  and

 

  1. Type in the text Hello! And, my name is Kitty or your choice of name before placing both in the Scripts area.

Figure 46: Blocks to make the sprite talk

It would be nice to give the Sprite a name.

To do so, click on the   button at the bottom left of the cat sprite icon and type in the text Kitty or your name of choice in the box.

Figure 47: Changing the name of a sprite

Click on the Green Flag at the top right-hand side of the computer screen and see what happens.


A MOVING SPRITE

Now we want to get the sprite moving.

Go to the Motion folder and select the Move block.  Change the number of steps to 50.

Attach this block to the rest of the blocks in the script area and start the program.

Figure 48: Adding motion to the sprite

To increase movement of the Sprite and to give the impression of walking, go to the Control folder and select the Wait block.

Place this block in the Script area with the addition of some extra Move blocks:
However, we now have a problem with the Sprite. As you may have noticed, if we keep using this script, the cat will keep moving until it almost disappears off the screen.  So, we have to put in an extra command that will bring our cat back to the center when (s)he reaches the edges of the stage!

The screen is divided into X (horizontal) and Y (vertical) coordinates. the center of the screen being (X) 0 (Y) 0 and the numbers being positive or negative depending on their positioning.

The coordinates for the centre of the screen are X(0) and Y(0). A positive X value means that an object will move to the right, a negative X value brings an object to the left. A positive Y value makes an object go up. A negative Y value makes an object go down Figure 49.  

Figure 49: A sprite at coordinates (0,0)

 

Move the sprite around the screen and observe as the values of the X and Y coordinates change just below the sprite icon at the bottom right side of the Script area.

This function allows the user to position different sprites at different locations. Hence, we can place a script or block at the beginning of the set of commands that will instruct the cat to move back to the centre of the screen every time we select the Green Flag.

Figure 50: Script with additional blocks to make the sprite move

 

Test the effectiveness of this new code by using the mouse to position the Sprite towards the bottom or top of the screen before clicking on the Green Flag icon.  Different methods other than a Green Flag can be used to start a Script using the ‘When’ commands in the event folder. For instance, when the Space Bar or Arrow Keys are hit.

Replace  with

(From the Events folder) in the Script.

Now click the Space Bar on the computer keyboard to start the program.


Saving the project
Go to the File folder


Select ‘Save to your computer’.

 

Figure 51: Saving your project

 

Type in Moving cat or your own name for your cat icon in the section labelled “Filename”.
Then choose where you want to store it, such as Desktop or My Projects followed by selecting the save icon.


Last modified: Tuesday, 21 December 2021, 3:13 PM