Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Keeping Time (Part 2 of 2)

Choose an Add-On
play_circle_filled
Spinning Obstacle
Create a more challenging game by making an obstacle spin.
arrow_forward
play_circle_filled
Overtaken
Create an obstacle that slowly grows throughout the game.
arrow_forward
play_circle_filled
Revenge
Program the goal sprite to chase the player sprite.
arrow_forward
play_circle_filled
Keeping Time (Part 1 of 2)
Create a timer to keep score for this game, and program a way to store the fastest time.
arrow_forward
play_circle_filled
Keeping Time (Part 2 of 2)
Create a timer to keep score for this game, and program a way to store the fastest time.
arrow_forward
play_circle_filled
Redesign Your Maze
Change the look of the maze or draw your own!
arrow_forward
play_circle_filled
Tell a Story
Engage game players with an exciting story for your game.
arrow_forward
  • 1. Remix the Maze Starter Project
  • 2. Following the Mouse Pointer
  • 3. Stay Inside the Lines
  • 4. Using If-Statements to Win
  • 5. Add-Ons
  • 6. Reflection
  • 7. Wrap-up: Maze Game
  • 8. Wrap-up: Share Your Project
  • 9. Wrap-up: Show Your Project
arrow_backward Back Next arrow_forward
Transcript

In this add-on, you’ll create a variable to store the fastest time.

To start, click on data, and select “make a variable.” Scratch has some variables already created, like the timer used in the last step. But, this time, you will make your own. Name it something like “Fastest Time,” then select “okay.” Drag the fastest time variable into the scripts editor. The “fastest time” variable will store the shortest amount of time taken to finish the maze. To set a new “fastest time,tell the computer to check if the value of the timer is less than the lowest score.” Drag out an “if” statement and a “less than” operator. Then, put the timer variable and the fastest time variable into this operator. This now reads, if timer is less than fastest time, then... If the timer is less than “fastest time,” then the value of the timer should become the new fastest time. Click on data, select a “set fastest time to,” block and add the timer variable.

Now this reads, “If the timer variable is less than “fastest time” then set “fastest time” to the value of timer. Now that you’ve coded this, add it to your program. Check this if statement when the player reaches the goal sprite.

Finally, set the timer to something really high. Right now, the low score is 0, and it’s impossible to get a time lower than 0. Click on data, find the “set fastest time to” block, and change it to something like 50. Click the block to test.

Now, the player is ready to set a new fastest time!

Look at that time… Can you beat it? Now, it’s your turn!

1. Create a “fastest time” variable. 2. Set a new fastest time using the fastest time variable, an if statement, a less than operator, a set fastest time to, and two “timer” blocks. 3. Set the starting fastest time.

Instructions
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!