Autotouch iPhone lua带有2个变量的Tap位置



有一个命令调用"tap(x,y)",我需要一种方法来组合行变量和列变量

代码:

--[[ Row Pos ]]--
r1 = 587.95
r2 = 383.05
--[[ Barracks Column ]]--
cb1 = 476.53
cb2 = 722.26
--[[ Barracks Variable ]]--
wizard = "r2" .. "," .. "cb1"
healer = "r2" .. "," .. "cb2"
tap(healer);
usleep(30000)
tap(wizard);
usleep(30000);

错误:

Bad Argument #2 to 'touchdown' (number expected, got string)

这意味着它想要数字,但我正在输入字符串,有不同的方法吗?

您不需要将这两个变量组合在一个字符串中。只需使用列和行变量:

-- Row Pos
r1 = 587.95
r2 = 383.05
-- Barracks Column
cb1 = 476.53
cb2 = 722.26
-- wizard
tap(cb1, r2) -- did you mean r1? I just used your example
usleep(30000)
-- healer
tap(cb2, r2)
usleep(30000)

请注意,列(x)首先给出。

对代码的一些注释:没有必要结束一行注释,如我的示例所示。此外,不需要分号,我省略了它。

如果您想使用一个同时收集两个参数的变量,可以使用一个表并对其进行解压缩:

local wizard = { cb1, r2 } -- { x, y }
tap(table.unpack(wizard))

现在可以为函数tap使用包装器,添加语法糖:

local old_tap = tap
function tap(location)
    old_tap(table.unpack(location))
end

要更进一步,请检查参数并以正确的方式调用函数:

local old_tap = tap
function tap(x, y)
    if type(x) == "table" then
        old_tap(table.unpack(x))
    else
        old_tap(x, y)
    end
end
-- now tap can be used both ways:
tap(cb1, r2) -- wizard
local healer = { cb2, r2 }
tap(healer)

最新更新