this function allows you to wait in nanoseconds
its just like a perfect wait
local function NanoWait (seconds)
if seconds <= 0.005 then
local TimeNow = os.clock()
while true do
if os.clock()-TimeNow >= seconds then
break
end
end -- this is for 0.005 seconds and lower.
else
task.wait(seconds) -- and this is for higher that 0.005 seconds (don't remove it).
end
end -- By QELPHT
you can use it by writing NanoWait() and but your time in it like this:
NanoWait(0.000001)
this is to check if you don’t believe in it:
input:
local time = os.clock()
NanoWait(0.000001)
print(os.clock() - time)
Sure, there are tricks like this so that your minimum wait time is less than the delta of each frame (task.wait is based on PostSimulation frequency) or ~0.03 seconds (deprecated global wait is based on old 30hz task scheduler), but there are two problems with it.
It’s pretty heavy to run.
If none of the existing wait or yield methods solve your use case, then you’re probably running into a timing problem that you need to fix with defensive architecturing instead.
Don’t rely on novelties like this in production-level experiences for your and your collaborators’ sanity’s sake, pretty please. The perfect wait is not waiting at all; code that’s more responsive towards context is better predictable and therefore maintainable.
This feels like almost a copy of my useless thing, it popping up to my notifications and seeing something similar to my title made me think that I have a clone??
I don’t remember if I’ve mentioned it was useless in the thread.
A better way to do these is to re-adjust your timings whenever the cycle restarts.