Ready-to-use Code ExampleRegionNumKVGaming

OCR Score Reader with History

Reads a numeric score from a screen region, keeps a persistent history in the KV store, and notifies on a new record. `Num.parseOcr` tolerates common OCR digit-recognition errors (e.g. "1,234" or "l234" still parse cleanly).

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.

-- OCR skor okuyucu / OCR score reader
-- Region.readAsString + Num.parseOcr ile OCR hatalarini tolere et

local scoreRegion = Region(800, 100, 280, 80)
local bestKey = "en_yuksek_skor"

Snap.screenRefresh()

-- Bolgeyi oku, OCR-tolerant sayiya cevir
local rawText = scoreRegion:readAsString()
local score = Num.parseOcr(rawText, 0)

if score <= 0 then
  toast("Skor okunamadi: '" .. rawText .. "'")
  return
end

-- Mevcut rekor ile karsilastir
local bestScore = KV.getNumber(bestKey, 0)

if score > bestScore then
  KV.set(bestKey, score)
  KV.increment("rekor_kirilma_sayisi", 1)
  System.vibrate(300)
  System.noti("Yeni rekor!", "Skor: " .. score .. " (onceki: " .. bestScore .. ")")
else
  toast("Skor: " .. score .. " (rekor: " .. bestScore .. ")")
end

-- Son 10 skoru append ile sakla
local history = KV.get("skor_gecmisi", "")
local newEntry = score .. ","
if #history > 200 then
  history = history:sub(-100)
end
KV.set("skor_gecmisi", history .. newEntry)

Implementation and Adaptation Notes

  • Before running, replace sample values such as image names, text, colors, coordinates, and file paths with your own macro values.
  • For examples that use Region or coordinates, retest the target area on different resolutions and DPI values.
  • Tune mScore, timeout, and scan rate in a test macro first, then move the verified values into the production macro.
  • Avoid overly wide Region areas; a tighter area scans faster and reduces false matches.