如何用变量字符串检查布尔值(由用户设置)?

用户将布尔值设置为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,..等)是全局变量时,这才有效.

相关文章

1.github代码实践源代码是lua脚本语言,下载th之后运行thmai...
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/...
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能...
localfunctiongenerate_action(params)localscale_action=cc...
2022年1月11日13:57:45 官方:https://opm.openresty.org/官...
在Lua中的table(表),就像c#中的HashMap(哈希表),key和...