计时器脚本在Roblox Lua中不循环
2021-7-20 19:1:17
收藏:0
阅读:145
评论:2
计时器脚本在2:29停止,不会继续倒数。它应该倒数到零,但在循环1次后会停止。while true do循环继续,但文本标签可能不会显示它,或者分钟和秒钟变量没有改变。我需要帮助让它工作。
local starterGui = game:GetService("StarterGui")
local Guis = starterGui.RoundTimer --包括时间文本标签。
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
点赞
用户13855913
我已经知道这一点了,但如果有人想知道怎么做:
while true do
wait(1)
local timeleft = game.ReplicatedStorage.Seconds.Value -- 获取秒数值
local minutes = math.floor(timeleft/60) -- 通过将秒数除以60获取分钟数
local seconds = timeleft%60 -- 通过使用60除余时间,获取剩余的秒数。
script.Parent.Text = string.format("%d:%02d", minutes%60, seconds) -- 将分钟和秒数格式化成计时器。
end
有关string.format()
的更多信息请看这里:https://developer.roblox.com/en-us/articles/Format-String
% /除余运算 的作用:
比如说你有90秒,并想要将其转换成1分30秒。你已经找出了通过时间left/60可以得出现在是一分的。通过使用timeleft%60
将时间left除以60后得到余数,因此得到了30。
2022-01-17 03:45:46
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
我认为总体逻辑没问题,所以没有理由在2:29停止,但格式方面有些问题,当我运行脚本时(一个片段),我得到了以下结果:
如你所见,: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