【问题标题】:Autotouch iPhone lua Tap position with 2 variablesAutotouch iPhone lua点击位置有2个变量
【发布时间】:2016-11-19 22:56:38
【问题描述】:

有一个命令调用“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)

这意味着它需要数字,但我正在输入字符串,我可以用其他方法吗?

【问题讨论】:

    标签: iphone lua autotouch


    【解决方案1】:

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

    -- 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) 列是第一个给出的。

    您的代码中的一些 cmets:不必结束一行 cmets,如我的示例所示。此外,分号不需要,我省略了它。

    如果你想使用一个变量来收集两个参数,你可以使用一个表并解压它:

    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)
    

    【讨论】:

    • 有没有一种方法可以在列和行中使用像向导这样的名称变量
    • 感谢我不太擅长的功能,我可以很容易地阅读该功能,所以谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2019-11-22
    相关资源
    最近更新 更多