Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how long is wait()?

Asked by 8 years ago

Alright, so let's say your code was:

while true do
wait()
print(hi)
end

how long does the

wait()

actually wait for?

4 answers

Log in to vote
5
Answered by 8 years ago

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.

0
This answer would be even better if you explained what you meant by deltas and gave an example! BlueTaslem 18071 — 8y
0
Edited to explain it. User#6546 35 — 8y
Ad
Log in to vote
2
Answered by 8 years ago

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())

Log in to vote
0
Answered by
Kryddan 261 Moderation Voter
8 years ago

wait() is equal to around 0,03 seconds, 30 times a second.

Log in to vote
0
Answered by 8 years ago

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.

Answer this question