lua - 计时器脚本不循环(Roblox Lua)
问题描述
计时器脚本在 2:29 停止,不会从那里倒计时。它应该倒数到零,但会在 1 个循环后停止。while true do 循环继续进行,但文本标签不会显示它,或者分钟和秒变量没有改变。我需要帮助来完成这项工作。
local starterGui = game:GetService("StarterGui")
local Guis = starterGui.RoundTimer --Includes the time textlabel.
local Seconds = 30
local Minutes = 2
repeat
wait(1)
if Seconds < 9 then
if Seconds == 0 then
Seconds = 59
Minutes = Minutes - 1
else
Seconds = Seconds - 1
end
Guis.Time.Text = tostring(Minutes)..":0"..tostring(Seconds)
else
Seconds = Seconds - 1
Guis.Time.Text = tostring(Minutes)..":"..tostring(Seconds)
end
until Seconds < 1 and Minutes < 1
解决方案
我看不出整体逻辑有任何问题,所以没有理由让它在 2:29 停止,但是格式化存在一些问题,因为这是我在运行脚本(片段)时得到的:
1:10
1:9
1:8
1:07
1:06
1:05
1:04
1:03
1:02
1:01
1:00
0:059
0:58
如您所见,:8、:9 和:059 的格式不正确。
像这样的东西可能会更好一些:
repeat
Guis.Time.Text = ("%d:%02d"):format(Minutes, Seconds)
wait(1)
Seconds = Seconds - 1
if Seconds < 0 then
Minutes = Minutes - 1
Seconds = 59
end
until Seconds < 1 and Minutes < 1
推荐阅读
- python - 将 tensorflow gpu 模型转换为 cpu 进行推理
- matlab - matlab类和数据管理
- reactjs - 解析服务器标头
- db2-400 - 为什么退出时没有关闭游标?
- java - HIbernate:持久化新对象时出现 java.sql.BatchUpdateException
- symfony - SF5 - 从 5.0 弃用到 5.2
- python - 我不明白我的列表迭代代码有什么问题。蟒蛇 3
- swift - Xamarin.iOS 以 72 dpi 拍摄照片
- python - Matplotlib:使用 fontproperties 名称更改 xticks 字体仅适用于第一个 xtick
- html - HTML - 如何让按钮打开不同的链接但制作通用的关闭按钮