Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local o_clock = os.clock
- local c_yield = coroutine.yield
- local c_running = coroutine.running -- note for line 9:
- local c_resume = coroutine.resume -- identical to "for Idx, data in pairs(Yields) do"
- local Yields = {}
- game:GetService('RunService').Stepped:Connect(function() -- every frame it runs this:
- local Clock = o_clock() -- the curtime is saved, with high precision (micro)
- for Idx, data in next, Yields do -- let's check on all the waits right now:
- local Spent = Clock - data[1] -- the elpsdtime is set to curtime minus starttime
- if Spent >= data[2] then -- if the elpsdtime achieves the waittime, then:
- Yields[Idx] = nil -- clear the sent data
- c_resume(data[3], Spent, Clock) -- resume the running function
- end -- end
- end -- end
- end) -- end
- return function(Time)
- Time = (type(Time) ~= 'number' or Time < 0) and 0 or Time -- if given a bad time value, it doesn't wait
- table.insert(Yields, {o_clock(), Time, c_running()}) -- sends the starttime, waittime, and running function
- return c_yield() -- stops the running function
- end
- Some more info (not part of the code):
- Heya. This is a module for Luau (i.e. Roblox) that optimizes the wait() command. All of these lines of code were written by Pyseph, but I have marked them up for personal viewing. Here is where I found this:
- https://devforum.roblox.com/t/custom-wait-the-best-solution-to-yielding/715274
- Again, I didn't write this. This is Pyseph's work.
- Suerte!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement