Created
July 22, 2019 05:19
-
-
Save Skaruts/ee3d96b94033c1774c44c4cc274daef5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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