如何使用脚本在roblox工作室中检查数值的位数



我正试图在roblox中制作一款破解电脑PIN的游戏。但我不知道如何检查数值有多少位数,所以我来这里询问。

如果你们想玩我的游戏,点击这里

我这么做是因为我希望零可以胜任这项工作,但不,他们不能

if game.ReplicatedStorage.Password.Value == {nil, nil, nil, nil} then
script.Parent.PlaceholderText = "Four Digits PIN"
elseif game.ReplicatedStorage.Password.Value == {nil, nil, nil, nil, nil, nil} then
script.Parent.PlaceholderText = "Six Digits PIN"
end

我假设Password.Value是一个字符串。您可以只使用长度运算符。

local password = game.ReplicatedStorage.Password.Value
local passwordLength = #password
assert(passwordLength > 0, "The password cannot be empty")
local numberWords = {
"One", "Two", "Three", "Four", "Five", "Six"
}
local message = string.format("%s Digit PIN", numberWords[passwordLength] or tostring(passwordLength))
local Placeholder = script.Parent.Placeholder
Placeholder.Text = message

您可以使用:math.ceil(math.log(game.ReplicatedStorage.Password.Value))

如果这对你不起作用,这里讨论了多种其他方法来解决这个问题:

https://devforum.roblox.com/t/best-way-to-find-how-many-digits-in-a-number/833942

最新更新