does this SafeWait make sense?

Posted by Jing Wu on Fri 03 May 2013 07:50 AM — 4 posts, 15,852 views.

Australia #0

function CommandSender:SafeWait(interval)
	if interval < 0.1 then
		interval = 0.1 -- wait minimum unit is 0.1 second
	end
	local startTime = socket.gettime()
	wait.time(interval)
	local usedTime = socket.gettime() - startTime
	interval = interval - usedTime
	if interval > 0 then
		ColourNote("white", "red", "wait used:" .. usedTime .. ", required more delay:" .. interval)
		self:SafeWait(interval)
	end
end


I found that wait.time sometimes returns earlier than the actual wait time, because, I guess, windows message issues?

Cheers,
Jing
Australia Forum Administrator #1
I think I would loop rather than recurse, just to be on the safe side.

You should be able to use the high-precision timer (see utils.timer) to see how much time has elapsed.
Australia #2
socket.gettime should do the same thing as utils.timer does.
From the test, I can see sometimes ColourNote outputs.
so can I say that wait.time is not reliable?

Cheers,
Jing
Australia Forum Administrator #3
It should be reliable, however timers are implemented with a 0.1 second granularity. I would be interested to see your exact figures for what you think is "not reliable".