尝试从一个区域中确定4个坐标。

我为《钢琴块2》创建了一个简单的宏,只是为了看看是否可以无限自动化。 我的代码如下:

search = true
region = {100, 500, 500, 1}
while search do
    findColorTap(0, 1, region);
    findColorTap(258, 1, region);
    findColorTap(16758018, 1, region);
    usleep(5000)
end

适用于所有三个方块。

-0表示墨黑色音符
-258表示特殊音符,其“击打点范围”更小
-16758018表示超加音符,其“击打点范围”更小

目前脚本将在屏幕上的1像素水平线上从起点到终点(100->500)检查每种颜色,并在返回所需颜色时点击该像素一次。

我很好奇如何仅从区域中取4个点,并以同样的方式检查这些点。 我还好奇,如果上述操作是可能的,那么Lua是否能够编译比检查区域更快或更慢的脚本。

我的想法是,一旦findColorTap返回我需要的值,其他检查实际上就是浪费宝贵的时间。但是,我也知道代码越复杂,我的手机就必须更努力地处理这些命令。

我试过了:

示例1

check = true

while check do
    note1 = getColor(80,500)
    note2 = getColor(240,500)
    note3 = getColor(400,500)
    note4 = getColor(560,500)
end

while check do
if note1 == 0 then
    tap(80,500)
elseif note1 == 258 then
    tap(80,500)
elseif note1 == 16758018 then
    tap(80,500)
    else
    end
end

这最终要么根本没有读取任何音符,要么在捕捉时失去了与游戏的同步。

示例2

function fct(startX, maxX, y, increment)
    for x=startX,maxX,160 do
        check=getColor(x,y)
        if check == 0 then
        return(x)
        end
    tap(x,y)
    end
end

v = true
repeat
fct(80,560,500) until
v == false

这个在检查正确且速度更快的同时,却在错误的位置敲击。

点赞
用户501459
用户501459

其他检查基本上是浪费宝贵的时间。但是,我也知道代码变得越复杂,我的手机就必须花更多的时间来处理这些命令。

你称之为“其他检查”的内容,远比你的代码复杂得多。

你不需要担心你有多少行代码,你需要担心计算上耗费资源的代码被执行了很多次。

Lua 是否能够比检查区域快速编译脚本或者慢些。

您是指运行速度更快。编译是在启动时完成一次,不会影响运行速度。

而且,检查四个像素比检查成百上千个像素要快得多。

我试过了

说出你尝试过什么对我们没有好处,除非你告诉我们为什么它不起作用。

while check do
    note1 = getColor(80,500)
    note2 = getColor(240,500)
    note3 = getColor(400,500)
    note4 = getColor(560,500)
end

while check do
    if note1 == 0 then
        tap(80,500)
    elseif note1 == 258 then
        tap(80,500)
    elseif note1 == 16758018 then
        tap(80,500)
        else
        end
    end
end

这看起来似乎永远不会离开第一个循环(除非你在getColor中设置check)。

此外,第二个循环中的每个分支都会产生完全相同的“tap”。

很难确定你在问什么,但如果目标是检查指定位置的颜色,然后根据找到的颜色到达另一个指定的位置,你可以像以下代码一样做:

-- 需要检查的点
points = {
    { x= 80, y=500 },
    { x=240, y=500 },
    { x=400, y=500 },
    { x=560, y=500 },
}

-- 将找到的颜色映射到结果的点击点
tapPoints = {
  [0]        = { x=80, y=500 }, -- 这些
  [258]      = { x=240, y=500 }, -- 应该
  [16758018] = { x=400, y=500 }, -- 不同!
}

while check do
    for checkPoint in ipairs(points) do
        local note = getColor(checkPoint.x, checkPoint.y)
        local tapPoint = tapPoints[note]
        tap(tapPoint.x, tapPoint.y)
    end
end
2015-12-10 20:53:58