如何解决如何遍历 TTS Lua 中的表?
所以,我有一个类似以下内容的表格:
PlaneToolTip= {['Vickers_0']={title="Vickers F.B.5 Gunbus",text="Vickers F.B.5 Gunbus Variant",row="Vickers",image="planes_creation"},['Vickers_1']={title="Vickers F.B.5 Gunbus",text="Vickers F.B.5 Gunbus Variant 1",typeguid="7a5d62",image="Vickers F.B.5 Gunbus Variant 1"},['Morane_0']={title="Morane Saulnier Type N",text="Morane Saulnier Type N Variant",row="Morane",['Morane_1']={title="Morane Saulnier Type N",text="Morane Saulnier Type N Variant 1",typeguid="dbf582",image="Morane Saulnier Type N Variant 1"},['Morane_2']={title="Morane Saulnier Type N",text="Morane Saulnier Type N Variant 2",typeguid="73c10f",image="Morane Saulnier Type N Variant 2"}}
你好,我使用Lua(Tabletopsimulator),想在表格中搜索一些东西,比如“title”。
for a,b in pairs (PlaneToolTip) do
for b,c in pairs (PlaneToolTip [a]) do
if c == "Morane Saulnier Type N" then
...
end
end
end
然后它应该输出所有合适的“typeguid”。如“dbf582”、“73c10f”。
感谢您的帮助 拉多安
解决方法
function get_typeguids(variant)
local typeguids = {}
for _,entry in pairs(PlaneToolTip) do
if entry.typeguid and entry.text:find(variant) then
table.insert(typeguids,entry.typeguid)
end
end
return typeguids
end
print(table.concat(get_typeguids("Morane Saulnier Type N"),","))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。