Bot Builders : Train Your Robot

Add a timer

  1. Good job so far! Now let's make your game more challenging.
  2. Let's add a timer that counts down to 0
  3. Start by making a new variable and name it timer

  1. Let's make a new script block to manager the timer.
  2. Start by resetting the timer to 30 when you start the game.
  3. Add the code block to your robot.

  1. What we want to do is to decrease the time by 1 every second.
  2. To do this, we'll be using a special type of loop.
  3. Go to the control blocks and attach repeat until <>
  4. This control block repeats the script inside until a certain condition.
  5. Our condition is that the loop will stop until the timer variable is 0.
  6. Go to the Operators blocks, and attach < [] = [] > inside.
  7. We can use this operator to compare (time) with 0.

  1. Attach wait (1) secs inside repeat until <>.
  2. Afterwards, decrease the time by 1 with change [time v] by (-1)
  3. Now try clicking the green flag icon and check the time value if it changes every second.