用户将 boolean 值设置为 true 或 false。
这样做(例如)
ElementNameone = true
ElementNametwo = false
ElementNamethree = true
等等。
现在我有一个从文件加载的字符串。名为 name 的字符串可以具有以下值:Nameone、Nametwo、Namethree 等。一次可以是其中任何一个。
现在我希望能够做到这一点
if Element .. name == true then
do something
除了我不知道如何正确地做到这一点。
我试过做
if not not ("Element" .. name) then
但它不起作用。
任何人都可以帮忙吗?
谢谢
最佳答案
尝试这个:
if _G["Element" .. name] == true then
-- do something
end
请注意,这仅在用户设置的变量(
ElementNameone
,.. 等)是全局变量时才有效。
关于string - 如何使用变量字符串检查 boolean 值(由用户设置)的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18602365/