有没有办法缩短这段代码?
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
PressKey ("a")
Sleep (50)
if not IsMouseButtonPressed(1) then
ReleaseKey ("a")
return
end
PressKey ("a")
Sleep (200)
if not IsMouseButtonPressed(1) then
ReleaseKey ("a")
return
end
...
next all the same with sleep values only changing
我想使用repeat-until,但我不能这样做,因为睡眠的价值在变化。有没有办法将睡眠值保存在表格中(即50,200,100,75,25,200),所以我可以在代码中使用Repeat-Until?我一直在努力搜索,但我是Lua的新手。感谢任何帮助,谢谢
答案 0 :(得分:1)
由于你想循环超出一系列超时,我不会使用repeat until
而是使用for
循环。最重要的是,您应该在完成列表后通知调用者所有超时都失败。
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
for _,duration in ipairs{50, 200, 100, 75, 25, 200} do
PressKey ("a")
Sleep (duration)
if not IsMouseButtonPressed(1) then
ReleaseKey ("a")
return
end
end
return "ERROR" -- You should somehow indicate timeout to the caller
end