Copyable Example Code
You can paste this into the code editor; still verify target image, region, color, text, and timing values in your own device flow.
-- Dialog: image picker
-- score: match threshold from 0 to 1 (0.85 = close match)
local cfg = Setting.builder()
cfg:setTitle("Choose images")
cfg:add("primary", ImagePicker("primary", "Main target image"))
cfg:add("fallback", ImagePicker("fallback", "Fallback target image"))
cfg:add("score", EditText("0.85", 1, "Match score (0-1)"))
Setting.setDialog(cfg:build())
Setting.show()
local primary = Setting.get("primary", "")
local fallback = Setting.get("fallback", "")
local score = math.min(math.max(tonumber(Setting.get("score", "0.85")) or 0.85, 0), 1)
if primary == "" then
toast("No image selected")
requestStop()
return
end
local param = FindParam.mScore(score):timeout(5000)
Snap.screenRefresh()
local region = Region()
local match = region:find(Asset.image(primary), param)
if not match and fallback ~= "" then
match = region:find(Asset.image(fallback), param)
end
if match then
click(match)
toast("Image found and tapped")
end