Sorry, we don't support your browser.  Install a modern browser

Time.time is quite inaccurate#1878

Time.time should according to the documentation be a more accurate version of os.time(). This isn’t the reality tough, when implementing a timer based on taking a start timestamp, then whenever the timer updates it calculates a diff from that start time and displays that. The time diverged by a few seconds every minute.
If this clock is supposed to be more accurate than os.time then there must be a bug somewhere.
By switching the timer to use os.time() instead there was no visible divergence from the real clock.

a year ago

With conversation in the scripting channel on the discord server it is clear that this happened because of fairly heavy load from the scripting in this module.
Here is an example that exemplifies how it fairly quickly diverges.

start_time_time = Time.time
start_os_time = os.time()
function onLoad()

print(“Starting timer with Time.time: “ .. start_time_time)
print(“Starting timer with os.time(): “ .. start_os_time)
–[[ print(‘onLoad!’) –]]
end

–[[ The onUpdate event is called once per frame. –]]
function onUpdate()
if Time.frame_count%1000 then
local elapsed_time_time = Time.time - start_time_time
local elapsed_os_time = os.time() - start_os_time;
print(“Elapsed Time.time: “ .. elapsed_time_time)
print(“Elapsed os.time(): “ .. elapsed_os_time)
print(“Diff: “ .. elapsed_os_time - elapsed_time_time)
end
– Adding some heavy work
data = int = 1,
string = “not particulary long string”,
struct = int = 2,
string = “recursive stuff this”,
}
}
for i = 1, 100, 1
do
local data_string = JSON.encode(data)
local data_again = JSON.decode(data_string)
end
end

a year ago
Changed the status to
Needs Clarification
a year ago

What the person is stating is that the time.time call should be more accurate than os.time when it comes to timing.

If I’m not mistaken, they are stating time.time drifts, or gets quite out-of-sync, with real time when a mod is processing a lot of computations that takes a bit of time to finish.

a year ago