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

我想知道如何回到第一个函数

我想在按钮6上执行3个功能;

首先,他去到TOPX和TOPY,在第二次点击时去到MIDX和MID,在第三次点击后去到BOTX和BOTY; 然后,如果我再次点击,他会回到第一个函数。

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

----------------------初始化----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CENTER = 32767
TOPX = 59305
TOPY = 54527
MIDX = 61764
MIDY = 58683
BOTX = 64060
BOTY = 63056
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- / 
function OnEventeventarg--MIDLANE
    if
    event ==“MOUSE_BUTTON_PRESSEDand arg == 6 then
         MoveMouseToMIDXMIDY--      PressMouseButton(1);
--          ReleaseMouseButton(1);
--              Sleep(20);
                    MoveMouseToMIDXMIDY);

function OnEventeventarg--BOTLANE
    if
    event ==“MOUSE_BUTTON_PRESSEDand arg == 6 then
          MoveMouseToBOTXBOTY);
--      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
点赞
用户2858170
用户2858170

你的措辞有点让人困惑。你不想“执行三个函数”。从你的文字中我理解你想每隔三次调用MoveMouseTo函数,并且每次传入不同的坐标。

所以将它们放在一个表里:

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)

...

2021-03-23 09:26:16