开发者

Lua: alternative to goto operator in Lua 5.1

开发者 https://www.devze.com 2022-12-07 22:35 出处:网络
Since World of Warcraft runs Lua 5.1, I\'d like to know if there is a way to get what I need without using the goto operator. This is my code: this code reads the contents of a tooltip line by line, a

Since World of Warcraft runs Lua 5.1, I'd like to know if there is a way to get what I need without using the goto operator. This is my code: this code reads the contents of a tooltip line by line, as if it were a text file

-- _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

If, due to a UI loading bug, at the end of the loop the line variable is equal to nil , just repeat 开发者_运维问答the loop so the line variable has a finite value. How can I achieve this in Lua 5.1?


How about:

while ((not line) or _G["UniScan_wpnTooltipTextLeft"..n]:GetText()) do 
...
0

精彩评论

暂无评论...
验证码 换一张
取 消