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

  1. The hero walks onto the alarm block. The block sends "alarm".
  2. The door hears the message and opens.
  3. The hero walks through, and reaches the goal behind the door.

What to build

  1. Press Open your game here, in the builder below, and go to level 2.
  2. Check that your alarm block comes before the door, so the hero reaches it first.
  3. Press the Objects button Objects, on the left of the builder, and click Goal.
  4. Click on your floor, behind the door. The hero can only reach it once the door is open.

How to add the test

  1. Press the Game button Game settings, under the map. It is the one with the gear.
  2. In Game Settings, find Scripts and press Tests Tests. Your test from the last chapter is there. Leave it.
  3. Press Code 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
  1. Press Save Save.

This test listens for "alarm", just as the door does. It waits a second, then asks: is the door open?

This makes a new game in your Lab and opens the builder right here. It is free.

Test it

  1. In the builder, press Play Play game, under the map.
  2. Walk the hero onto the alarm block. The door should open.
  3. Walk through and touch the goal.
  4. Look at the Test results drawer. Both of your tests should have a tick.
  5. Look under the builder. It should say that your tests passed.
If this happensWhat to do
The door does not openCheck the names. The block must say trigger "alarm" and the door must say when "alarm".
The door test has a crossCheck that your lock block's ID is Door, with a capital D or without.
Only one test has a tickBoth tests must pass in the same go. The old one needs the hero to touch the goal.

Make every goal and every test pass to finish this section.