lua - 我可以让我的 Lua 程序睡一天左右吗?
问题描述
我想让我的 mydicebot (by seuntje) Lua 程序在一天内睡觉,在赌了一天之后......就像
function sleep(n)
t = os.clock()
while os.clock() - t <= n do
-- nothing
end
end
function playsleep()
sec = math.random(80000,90000)
sleep(sec) -- around 86400 seconds
end
timestart = os.time()
dur = math.random(70000,80000)
function dobet()
if os.time() - timestart < math.random then
playsleep()
end
timestart = os.time() -- reset the time counter
end
但是当我在 dobet 函数中调用 playsleep 函数时
- 最终我无法单击程序中的任何内容,也无法移动另一个选项卡
- 而且 CPU 也不在休眠,甚至变得很忙
- 有时甚至在 90000 秒后仍然卡住
-- 问题 --
A. 那么我可以制作一个睡眠是真正睡眠的功能吗?
B. 能睡到 90000 秒吗?
C. 或者上面的变量“sec”的最大睡眠时间是多少?
解决方案
使用 posix 模块休眠:
posix = require("posix")
posix.sleep(86400)
但这仍然会阻止您的程序,您将无法单击任何内容。您需要提供有关您的计划的更多详细信息,以便获得更好的建议。
推荐阅读
- python - 我如何创建调用相互中断的函数的热键?
- java - 休息:如何处理数千个相同的请求
- node.js - Angular 源文件在浏览器中可见。如何隐藏?
- javascript - Slick Carousel - 在移动设备上幻灯片中的 5 个项目到 1 个项目
- python-3.x - 尝试获取占位符详细信息时如何访问幻灯片的形状元素?这是使用 Python PPTX 完成的
- javascript - 在 v-for 循环中访问元素的数据 (Vue.js)
- php - 为什么 Laravel 提供默认时间戳?
- django - Django Formset Validation - Formset 中的总和值
- r - 如何在 r 中创建一个新的键值对
- java - 为什么jar的父文件夹也出现在引用的库中?