如何使用多个函数 - GHUB/Lua

How to work with multiple functions - GHUB/Lua

我想知道如何返回到第一个函数
我想在按钮 6 中执行 3 个功能;
首先,他转到 TOPX 和 TOPY,第二次单击时,他转到 MIDX 和 MID,第三次单击时,转到 BOTX 和 BOTY;在此之后,如果我再次单击他 return 到第一个函数。

local  CENTER, MIDX, MIDY, BOTX, BOTY, TOPX, TOPY

----------------------Init------------------------------------------------------------------------------------------------------------------------------------------------------------------    
CENTER = 32767
TOPX = 59305
TOPY = 54527
MIDX = 61764
MIDY = 58683
BOTX = 64060
BOTY = 63056
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--/
function OnEvent(event, arg)
    --MIDLANE
    if  
    event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
         MoveMouseTo(MIDX, MIDY)
--      PressMouseButton(1);
--          ReleaseMouseButton(1);
--              Sleep(20);
                    MoveMouseTo(MIDX, MIDY);


function OnEvent(event, arg)
    --BOTLANE
    if
    event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
          MoveMouseTo(BOTX,BOTY) ; 
--      PressMouseButton(1);
--          ReleaseMouseButton(1);
                Sleep(20);
                    MoveMouseTo(CENTER, CENTER)
    --TOPLANE
    elseif
    event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
         MoveMouseTo(TOPX,TOPY) ; 
--      PressMouseButton(1);
--          ReleaseMouseButton(1);
                Sleep(20);


            end
        end
    end 
end

你的措辞有点混乱。您不想“执行 3 个功能”。根据您的文字,我认为您想每隔三次用不同的坐标调用 MoveMouseTo

所以将它们放入 table:

button6Coords = {
  {x = TOPX, y = TOPY},
  {x = MIDX, y = MIDY},
  {x = BOTX, y = BOTY},
}

然后有一个全局计数器,它会在您每次单击按钮 6 时递增。

counter6 = 0

在事件处理程序中:

...

if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
  counter6 = counter6 % 3 + 1
  local coords = button6Coords[counter6]            
  MoveMouseTo(coords.x, coords.y) 

...