Lap time problem (cannot get milliseconds from Timer)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Suleymanov

Hope you are doing great. My problem is I cannot get milliseconds from “Timer” as it doesn’t run accurately when I set the wait time to 0.01 because of insufficient FPS rate. I also tried “OS.get_ticks_msec()”, it runs the timing well, but this time I have another problem - I cannot reset it every time the car crosses the finish line. I also need resetting every time “ms” reaches 1000 (if > 999) to dial-up “sec” and start from zero.

My question is - are there ways to “restart” OS.get_ticks_msec(), and if not, how would you implement lap timing? I need 3 digits of “millisecond” value.

Thank you!

:bust_in_silhouette: Reply From: Matthew Hazlett

You will have to make your own timer class:

in it set the start time and when the lap is over subtract the two numbers, something like this

var start_time

func start():
     start_time = OS.get_ticks_msec ( )

func end():
     return OS.get_ticks_msec ( ) - start_time

Thanks, I’ll try that!

Suleymanov | 2020-07-12 08:34