I've been scratching my head at this for several hours. So i have a script that i'm calling a function 625 times but that causes lag so i want to delay each iteration of the for loop by 5 seconds. Any help would be great.
Asked
Active
Viewed 3,813 times
0
-
1Have you looked at this question: http://stackoverflow.com/questions/17987618/how-to-add-a-sleep-or-wait-to-my-lua-script – J. P. Petersen Nov 19 '16 at 20:16
1 Answers
2
I use this little function for second-resolution delays.
function os.sleep(sec)
local now = os.time() + sec
repeat until os.time() >= now
end
EDIT: Added msec version (approximate -- not very precise)
function os.sleep(msec)
local now = os.clock() + msec/1000
repeat until os.clock() >= now
end

tonypdmtr
- 3,037
- 2
- 17
- 29
-
1Millisecond Resolution can be achieved by using `os.clock()` instead of `os.time()`. – ATaco Nov 29 '16 at 00:47
-
Updated answer to include this version also. Thanks. However, it should be noted that according to the Lua reference, the value returned is only an approximation. – tonypdmtr Nov 29 '16 at 08:18