提问人:user3713179 提问时间:12/7/2022 最后编辑:Zakkuser3713179 更新时间:12/7/2022 访问量:336
Lua:Lua 5.1 中 goto 运算符的替代品
Lua: alternative to goto operator in Lua 5.1
问:
由于《魔兽世界》运行的是 Lua 5.1,我想知道是否有办法在不使用运算符的情况下获得我需要的东西。这是我的代码:此代码逐行读取工具提示的内容,就好像它是一个文本文件goto
-- _G["UniScan_wpnTooltipTextLeft"..n]:GetText() return the text at n line
local line, n = nil, 1
while (_G["UniScan_wpnTooltipTextLeft"..n]:GetText()) do ::redo:: --As long as there are lines of text
if string.find("Durability", _G["UniScan_wpnTooltipTextLeft"..n]:GetText()) then
line = n - 1
break
end
n = n + 1
end
if not line then goto redo end
如果由于 UI 加载错误,在循环结束时 line 变量等于 ,只需重复循环,使 line 变量具有有限值。如何在 Lua 5.1 中实现这一点?nil
答:
0赞
Dan Bonachea
12/7/2022
#1
怎么样:
while ((not line) or _G["UniScan_wpnTooltipTextLeft"..n]:GetText()) do
...
评论
0赞
user3713179
12/8/2022
不起作用!需要像递归函数这样的人
下一个:在给定时间内正确回答
评论
string.find