We have seen how snap can be programmed to wait for a certain time before reporting anything. snap also allows us to do the converse: to report how long a program takes to finish. In the "Sensing" palette, you will see a command called reset timer
and a reporter called timer
:
timer
reporter (click the checkbox), and you should see a timer ticking away in the top left corner of the stage. It's been ticking ever since you opened snap, and it counts in tenths of a second:This script will reset the timer whenever the green flag is pressed. The sprite will say "Hello!" for 1 second, then say the current time (less 1 second to account for how long the sprite said "Hello!").
If we replace "Hello!" with a reporter, then the sprite will say the value reported by reporter, and one second later, it will say how long the reporter took to generate that response: this is the timing information that we need for the upcoming pages in this lab.