60?
100?
Anyone have an exact number?
SOLVED
I realised I could just write something up really quick to find the number
val = 0
spawn(function()
while wait() do
val = val + 1
end
end)
wait(1)
print(val)
The answer is about 30 by the way, in case anyone is interested.
Not always 30 though due to lag and what not.
Got:
print(1/wait()) --> 29.020866914293
Expected:
print(1/(settings().Lua.DefaultWaitTime)) --> 33.333333333333
Due to the way roblox’s scheduler works, you may not always resume in the moment you expect.
Not roughly 30, wait() fits between 0 and 30 times inside wait(1), the exact amount of times is undefined. It is not guaranteed for wait() to resume at the moment that you expect. If you are planning on using this in a loop with wait(), consider keeping track of when you started and then wait until that time has passed, like so:
local start = tick()
while tick() - start < duration do
local t = (tick() - start) / duration -- value between 0 and 1
-- do your thing
wait() -- or for tighter loop: Heartbeat:Wait(), or RenderStepped:Wait(), or Stepped:Wait()
end
This will ensure you always loop for a certain amount of time and will allow you to do an operation at each time interval too. This is much better than simply for i = 1, 30 do ... wait() end
because this will not be guaranteed to be 1 second of total time.
Realistically, I’m surprised Roblox has a yielding function at all. I mean, from what I’m aware of, in pretty much every other language or game engine out there, there isn’t even something like that. I could be wrong, it’s interesting.
Pretty sure UE4 has a Delay function that does the exact same thing.
many languages have a sleep function, such as python’s in time:
import time
time.sleep(2) # sleeps for 2 seconds
oof. I completely forgot it’s referred to as “sleep” in most cases, and considering the fact I actually did Python quite a bit in the past, totally forgot about that. xd
But cool stuff.
Adding my quick two cents here.
If you go into Studio in settings under Lua the DefaultWaitTime is listed there. By default rounded it is 0.03. Which is equal to 33 times per second.
So if you haven’t changed that setting it is roughly 33 wait()'s in a wait(1)