Skip to content

Instantly share code, notes, and snippets.

@Skaruts
Created July 22, 2019 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skaruts/ee3d96b94033c1774c44c4cc274daef5 to your computer and use it in GitHub Desktop.
Save Skaruts/ee3d96b94033c1774c44c4cc274daef5 to your computer and use it in GitHub Desktop.
class Stopwatch:
var start_time = 0
var stop_time = 0
var counting = false
func start():
counting = true
stop_time = 0
start_time = OS.get_ticks_msec()
print(" --- Starting stopwatch at: %d ---" % [start_time] )
func stop():
if counting:
stop_time = OS.get_ticks_msec()
var elapsed = stop_time - start_time
var minutes = elapsed/60000
var seconds = elapsed/1000
var miliseconds = elapsed-seconds*1000
print(" --- Stopping stopwatch at: %d ---" % [stop_time] )
print("%02d:%02d:%04d | %04d" % [minutes, seconds, miliseconds, elapsed])
counting = false
else:
print("WARNING: requested stopwatch stop(), but not timing anything.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment