Triggering actions

Programming with Scratch Jr - Lesson 3

Objectives

  • To investigate different ways of triggering movement with code
  • Program two sprites to interact with each other
  • To use logical reasoning to predict the behaviour of simple programs

Lesson Resources

Introduction

Recap the last lesson. What did we create? What was different about our project last week?  We used multiple sprites.

With your tablet connected to your screen, start a new project and select the savannah background, remind them how to delete Scratch the cat and choose a new sprite appropriate for this scene, such as the elephant, zebra or giraffe. Add some simple code asking for suggestions from the students, how should our sprite move? Would that look realistic?

 

 

Let’s add another sprite like we did in the last lesson, take their suggestions for which one, how did we get several sprites to all start at the same time last week? The Green flag block let us send a start command to all algorithms that it’s linked to. Add this to your second sprite and take their suggestions for the rest of code for that character.

We used the red repeat forever block at the end of our algorithms last week, but it’s not the only red block available. The other one that you initially see is the end program block.

 

 

This doesn’t actually do anything but it does show that it’s the end of the code and is good practice to use it. As the children get older and learn other coding languages this is common practice, so it’s a feature to get them into the habit of using now (if they are not repeating things).

 

 

Main task

Now take a look at the other yellow blocks, these are all trigger blocks that can make things start to happen. Discuss with a partner, what do you think each block means and how could you use it in a program?

 

 

As we know, the green flag block starts the code it’s attached to when the green flag button is tapped.

 

This block starts the code it’s attached to when you tap on the sprite in the project window.

 

This block starts the code it’s attached to when one sprite bumps into another sprite.

 

This block sends a trigger message that can be received by any sprite in your project. There are six colours you can choose from, which allow six different messages to be sent in a project.

 

This block partners the send message block above. This is the receive message block. The code it’s attached to will only start when it receives a message of the same colour.

 

You can liken messaging in ScratchJr to a routine many people use in circle time, where an object is passed around and you only speak when you are holding the object. Passing the object is sending the message, holding it is you receiving the message to speak. You can demonstrate it nicely with real envelopes too. Put big coloured dots on them plus a message. Perform a short sequence of actions and then pass the envelope to a child, they can only perform the actions on the envelope when they receive it.

Alternatively you can print off examples of the messaging blocks (p.11 - 16 and p.19 -24) and hand write instruction messages below them.

 

 

Today we are going to use the bump and message blocks to make two sprites meet each other and have a short conversation.

Ask the students to start by choosing a nice background, a boy sprite and a girl sprite.

 

 

We want these sprites to meet and greet each other, what blocks do you think we might need to make them meet? First, they need to move so they can meet. Let’s code the boy to walk up to the girl, what block should we start with? how far do you think he needs to travel to the right? (this obviously will depend on their starting positions).

We’ll start things with the green flag and test out what distance is needed to get the boy to walk to the girl and be in contact with her, then end the code. E.g.

 

 

Next, switch your girl sprite. Add a when bump sprite block as her starter block and then a purple speech bubble block and add a greeting to the boy in it.

 

 

You can follow this with a second speech bubble if you want to, ask a question with this one.

 

 

Then add a send message block (you can leave it on the orange envelope) and then end the code.

 

 

The send message block is a trigger for something new to happen, what do you think it will start? It’s going to make the boy reply to the girl at the correct time. So now switch back to the boy sprite.

We are going to write a second algorithm for him that starts with the receive message block.

 

 

He needs to answer her question, so let’s do that with a speech bubble, and then end the code and test the whole program so far.

 

 

It’s likely you’ll see a little problem with things when you test it, the conversation will keep repeating between the two sprites, can we debug this? Why is it happening? As the characters remain touching after the boys movement across the screen, it keeps triggering the girl’s code to start again as it starts when she is touching another sprite. How could we solve this so they only have their conversation once?

 

 

We could simply add a movement block to the girl’s code, after she’s finished speaking, so she won’t be in contact with the boy sprite anymore.

 

 

Ask the students to have a go at getting their own sprites to have a simple conversation using the message blocks.

Some students might be able to extend the conversation by using further, different coloured message blocks back and forth between the characters, take a look at this example video. You can pause and rewind it to talk it through with the pupils to show where all the messages go.

 

Plenary

Review the lesson and the pupils’ understanding. What new features in ScratchJr have we learnt about today? The new key things are the trigger blocks, specifically the bump and message blocks and also the end block. Who managed to send at least one message that made another sprite do something? Did anyone manage to send more than one message to make their conversation longer? If any pupils managed this and you have the facilities, show their work on your big screen and ask them to explain how they have used messages.

Finally, the next step on from this type of project is to add more scenes and make it into a longer story. This is something we’ll tackle in our next lesson!

< Previous Lesson

Next Lesson >