Objective

On completion of this lab you should be familiar with using Scratch to write simple programs demonstrating flow of control (i.e. Sequence, Selection and Iteration) and basic event handling.

Basic Flow of Control

  • Your lecturer will show you how to open up the Scratch editor.

  • With the editor open, you will work on the SomethingFishy1 exercise from lectures.

Updating your Sprite from a cat to a fish

  • Click on the new Sprite icon as shown in the screen shot below:

Selecting a new Sprite

  • When the Sprite Library appears, click on the Animals category and select one of the fish sprites.

Animal Sprites

  • You will now have two sprites...the cat and the fish.

  • Right click on the cat sprite (as shown in the screen shot below) and select delete from the context-sensitive menu.

Delete the Cat Sprite

Adding Event Code

  • In the Scripts section, click on the Events button (the orange one). A list of Events will appear:

Events in Scratch

  • Drag the when green flag clicked to the script area, as shown below:

Using Events in Scratch

Getting the fish to talk

  • In the Scripts section, click on the Looks button (the light purple one).
  • From the list presented, drag the appropriate statements and make the necessary changes so that your code looks like this:

Using Events in Scratch

Test your program

  • Click on the green flag to run your program.
  • Does it work as expected?
    • Does your fish say "I'm a fish" and pause for 2 seconds?
    • Does your fish then say "I'm a lovely fish!" and the program stops running?

Saving your work

  • Select File from the menu bar, followed by Save As....
  • When the window appears, give your file the name SomethingFishy1 and click the Save button.

Flow of Control and Event Handling

  • Now that you have successfully written your first Scratch program, we will work on the SomethingFishy2 exercise from lectures.

Create a new file

  • From the File menu, select the New option. As you have saved your work in the previous step, if you are asked to discard the contents of the current project, you can say OK.

Fish Sprite

  • Add a fish sprite.
  • Delete the cat sprite.

Adding Code

  • Add the following code:

SomethingFishy2

Test your program

  • Click on the green flag to run your program.
  • Does it work as expected?
    • Does your fish say "Who am I?"
    • Does your fish, if you press the a key, say "I'm a fish with a five second memory!" and pause for 5 seconds, followed by saying "I've forgotten who I am!".
    • Does your fish, if you press the b key (or any other key), do nothing?

Saving your work

  • Save your work, calling the file SomethingFishy2.

More on Flow of Control and Events

  • Now that you have successfully written your two Scratch programs, try your hand at the SomethingFishy3 exercise from lectures.

SomethingFishy3

  • Create a new file.
  • Add a fish sprite
  • Delete the cat sprite.
  • Add the following code:

SomethingFishy3

Test your program

  • Click on the green flag to run your program.
  • Does it work as expected?
    • Does your fish say "Who am I?"?
    • Does your fish, if you press the a key, say "I'm a fish with a five second memory!" and pause for 5 seconds?
    • Does your fish, if you press the c key, ignore it?
    • Does your fish, if you press the b key, say "You have been told who I am!" and the program ends?

Saving your work

  • Save your work, calling the file SomethingFishy3.

Exercise

  • Create a new Scratch project.

  • Using a bat sprite, write the following program:

    • Say, "I am a bat!"
    • Repeat the following forever:
      • If the n key is pressed, say "I am nocturnal" for 2 seconds.
      • If the h key is pressed, think "Halloween is my favourite time of the year!".

Solutions

  • The solutions for this lab are here.

  • They will download in zip format and will need to be unzipped to see the individual files.