Trip the alarm
ChallengeThings that talk to each other
Your level 2 has a block that sends a message, and a door that listens. This challenge checks that they work together.
It is in your own game. As in the last chapter, your game checks it with a test that you write.
What should happen
- The hero walks onto the alarm block. The block sends "alarm".
- The door hears the message and opens.
- The hero walks through, and reaches the goal behind the door.
What to build
- Press Open your game here, in the builder below, and go to level 2.
- Check that your alarm block comes before the door, so the hero reaches it first.
- Press the Objects button
, on the left of the builder, and click Goal. - Click on your floor, behind the door. The hero can only reach it once the door is open.
How to add the test
- Press the Game button
, under the map. It is the one with the gear. - In Game Settings, find Scripts and press Tests
. Your test from the last chapter is there. Leave it. - Press Code
. Under your old test, leave a blank line, then type these three lines.
when "alarm"
wait 1 second
test "The door opens when the alarm goes off" if the {Door} is open- Press Save
.
This test listens for "alarm", just as the door does. It waits a second, then asks: is the door open?
Test it
- In the builder, press Play
, under the map. - Walk the hero onto the alarm block. The door should open.
- Walk through and touch the goal.
- Look at the Test results drawer. Both of your tests should have a tick.
- Look under the builder. It should say that your tests passed.
| If this happens | What to do |
|---|---|
| The door does not open | Check the names. The block must say trigger "alarm" and the door must say when "alarm". |
| The door test has a cross | Check that your lock block's ID is Door, with a capital D or without. |
| Only one test has a tick | Both tests must pass in the same go. The old one needs the hero to touch the goal. |

