Lua基础知识:如何循环?

嗨,我是一个新手,正在尝试使用名为AutoTouch的Lua语言从宏应用程序iOS/Android创建自动化脚本 https://autotouch.net/server/doc/en.html#autotouch-document。我不知道从哪里开始,有没有像这样的Lua函数?在整个屏幕上搜索颜色然后轻击它。脚本类似于这样

loop
color = PixelSearch(xcoord,ycoord,#somergbColor codes)
如果(color)在屏幕上找到它然后
    点它

否则
   点击传送技能/步行搜索目标按钮

endif
endloop

end
点赞
用户88888888
用户88888888

循环并不太具体。您可以使用 AutoTouch 提供的 findColor(color, count, region)getColor(x, y) 以两种方式执行内部操作(根据我的意见,getColor(x, y)getColors(locations) 更快),因为返回值。但如果开发人员没有提供用于处理较低和无符号整数的字节数组 API,则会出现问题。

findColor() 仅能查找最多一个像素。

local target = 0x447111;
local location = findColor(target, 1);
local first = location[1];

if location and first then
    touchDown(1, first[1], first[2]);
else
    --我不明白这个动作的用途?
end

因此,如果您想手动查找您的颜色,可以使用 getColor()

local target = 0x447111;
local w, h = getScreenResolution();

local broken = false;

for y = 1, h do
    for x = 1, w do
        local cur = getColor(x, y);
        if cur == target then
            broken = true;
            break;
        end
    end
    if broken then
        break;
    end
end

if broken then
    touchDown(1, 1, 1);
end
2017-04-08 17:59:42