Alright, so let's say your code was:
while true do
wait()
print(hi)
end
how long does the
wait()
actually wait for?
Alright, so let's say your code was:
while true do
wait()
print(hi)
end
how long does the
wait()
actually wait for?
I want to clear something up here. wait() isn't actually any set amount of time - It sticks the thread on the scheduler until the next heartbeat (It's put on with a time of 0).
Typically this will be about 0.03 seconds, because that is the time for the scheduler heartbeat, but if you have performance-intensive code with no yielding, it can wait for up to a whole 10 seconds. Make sure you use the return from wait as the delta to help your code take this into account.
The delta is the actual amount of time that was waited, and can be used as a scale. If you want something to move at a rate of 10 per second, then the rate for every iteration is 10*delta. This has good uses in things such as timeOfDay scripts.
local minutes = 60*8 -- Start at 8am
while true do
local delta = wait();
minutes = minutes + delta*3;
game.Lighting:SetMinutesAfterMidnight(minutes);
end;
That would make the game's time progress at a rate of 3 minutes per second, no matter how laggy the server gets.
Each wait() produces a different time but all around 0.03 seconds as it has been said before. You can check how long each print actually waits using print(wait())
wait() is equal to around 0,03 seconds, 30 times a second.
Traditionally a wait() is equal to 0.029999999999999999. This is 100% optional. You have the ability to change the default time of a wait in your studio's Lua option tab.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
This answer would be even better if you explained what you meant by deltas and gave an example!
Edited to explain it.