好的,我需要在lua脚本中(例如)等待10个人。有什么办法吗?
现在,我使用以下简单函数(非繁忙等待)socket
:
function my_utils.sleep(sec)
socket.select(nil, nil, sec)
end
但似乎其“最小睡眠时间”是毫秒。
范例1:
for x=0,2*math.pi,0.008 do
misc.printus()
misc.sleep(0.001)
end
输出:
0.022654
0.023654
0.024654
0.025654
0.026654
0.027654
0.028654
0.029654
0.030654
0.031654
0.032654
...
不错!
范例2:
for x=0,2*math.pi,0.008 do
misc.printus()
misc.sleep(0.0001)
end
输出:
0.537089
0.537089
0.537089
0.537089
... --(lots of)
38089
0.538089
0.538089
0.538089
0.538089
0.538089
0.538089
... --(lots of)
0.538089
0.577091 -- (jumps over 0.04 second!)
0.577091
0.577091
0.577091
0.577091
... --(and so on)
有人可以给我一些解释(大约跳0.04秒)吗?
Lua使用操作系统提供的时间服务。可用的分辨率通常不是很高,并且感觉随着时间在Lua级别上跳跃。
想象一下具有分钟分辨率的壁钟。它不能用于测量毫秒间隔。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句