Learning Intention

  • I can broadcast a message.

Introduction

What did we learn to do last week? (ask and respond using if-then-else). This week we will build on our ask and respond with if-then-else. However, we will learn another new skill: we will learn to broadcast. What does broadcast mean? In the Ohbot programming software it means to send a message from one sequence of code to start another. This allows the same sequence of code to be started from multiple places in your program. We will learn how to broadcast a message called 'well done'.

Teacher Input

Code broadcasting a well done message

First, we need to go to the Events palette and use New Message to create a message which we will call 'well done'. We will need to use the instructions `broadcast well done` and `when I receive well done`, as well as the usual start instruction `when green flag clicked`. Ohbot will ask the question 'What is 8x2?'. Again we will use an if-then-else statement. If the answer is 16 then we will broadcast our message 'well done'. Initially our broadcast will be Ohbot saying a congratulatory message. If the answer is anything other than 16 it will say an appropriate response to the wrong answer. File, Save As - 'broadcast well done'.

Activities

1.

Can you write code to broadcast your own message?

Creating a new broadcast message on the Events palette

Extension

We can take this one step further by adding sound and motion instructions to the broadcast so that Ohbot's response is even more appropriate, e.g. we can broadcast a round of applause and a head nod. Similar to our work last week, can you write some code to make Ohbot make a sound and nod its head when it receives the message 'well done'?

Broadcast code with added sound and head nod

Plenary

Questions:

  • How did you find today's lesson?
Ohbot image

Key Points

  • Broadcasting sends a message from one sequence of code to start another.
  • Create messages with New Message on the Events palette.
  • `broadcast [message]` sends it; `when I receive [message]` starts the code that responds.
  • The same sequence can be started from several places in a program without duplicating it.
  • Broadcasts combine naturally with if-then-else to react to a correct or incorrect answer.

Need Help?

If you're stuck on any part of this lesson, check out these resources:

Ohbot