Wake the guard

ChallengeThings that happen

This guard has the right steps, but they happen at the wrong times. Your job is to fix it.

What should happen

When the script is right, the game goes like this.

  1. The game starts. The guard stands still.
  2. The hero walks toward the guard. The guard sees him, shouts "Who goes there?" and jumps.
  3. The hero swings his sword at the guard. The guard yelps "Ouch!"

What happens now

The two events are the wrong way round.

When this happensThe guard does thisIt should do this
The guard sees the heroYelps "Ouch!"Shout "Who goes there?" and jump
The hero swings at itShouts "Who goes there?" and jumpsYelp "Ouch!"

How to fix it

You change a when line by picking a new one from a list.

  1. Look at the top left of the code box. Press Code Code, if it is not picked already.
  2. Find the when line above say "Who goes there?". It says when the {Hero} swings at me.
  3. Click the small arrow at the end of that line. A list of events drops down.
  4. In the list, click when I see the {Hero} within 5 blocks. The line changes.
  5. Now find the when line above say "Ouch!". It says when I see the {Hero}.
  6. Click the small arrow at the end of that line.
  7. In the list, click when the {Hero} swings at me.

Leave the last line, trigger "ouch", alone. It tells the goals that the guard yelped.

​
​
trigger "ouch"

Goals0 of 2 passed

  • The guard wakes up when it sees the hero: not checked yet
  • The guard yelps when it is hit: not checked yet

Press Play and make every goal pass. A goal is checked when its moment in the game comes.

Test it

The goals show under the little game. They are checked when the guard is beaten.

  1. Press Play Play this script.
  2. Click the little game, so the arrow keys work.
  3. Hold the right arrow key to walk the hero toward the guard. The guard should shout and jump.
  4. Keep walking until the hero is about one block from the guard.
  5. Press the X key to swing the sword. The guard should yelp, and then it is beaten.

Both goals should now have a tick. If one has a cross, press Stop Stop, check your two when lines, and try again.

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