仅在 os.time() 中显示最后一位数字
Show last digit only in os.time()
我正在尝试编写一个每秒打印不同内容的函数。
最简单的方法(我认为)是检查整数是偶数还是奇数。
- 对于偶数,它应该打印 'x'。
- 在奇数上,它应该打印 'y'。
我的问题是我无法弄清楚如何将 os.time
的整数值更改为仅显示最后一位数字(仅显示 0 到 9),因此我可以轻松地在我的代码中实现它。
这是我目前拥有的:
local seconds = os.time() --but only show last digit, e.g. 0 to 9
function changeStr()
if (seconds % 2 == 0) then
print("x")
else
print("y")
end
end
how to change the integer value of os.time to only show me the very last digit (only show 0 to 9)
除以10取余。那只会给你第 10 位。
seconds % 10
如果你想要一个包含时间最后一位的字符串,试试
string.sub(os.time(),-1)
我正在尝试编写一个每秒打印不同内容的函数。
最简单的方法(我认为)是检查整数是偶数还是奇数。
- 对于偶数,它应该打印 'x'。
- 在奇数上,它应该打印 'y'。
我的问题是我无法弄清楚如何将 os.time
的整数值更改为仅显示最后一位数字(仅显示 0 到 9),因此我可以轻松地在我的代码中实现它。
这是我目前拥有的:
local seconds = os.time() --but only show last digit, e.g. 0 to 9
function changeStr()
if (seconds % 2 == 0) then
print("x")
else
print("y")
end
end
how to change the integer value of os.time to only show me the very last digit (only show 0 to 9)
除以10取余。那只会给你第 10 位。
seconds % 10
如果你想要一个包含时间最后一位的字符串,试试
string.sub(os.time(),-1)