Aller au contenu principal

MatchResult:getRegion()

Returns the matched region as a Region object.

Description

The getRegion() method returns a Region object that represents the rectangular area where the match was found. This region includes the position (X, Y) of the top-left corner and the dimensions (width, height) of the matched area.

The returned Region can be used to:

  • Perform further searches within the matched area
  • Capture a screenshot of just the matched region
  • Define a sub-region for other operations
  • Build a fitted search area for faster repeated matching

Signature

getRegion(): Region

Returns

Region - A Region object representing the rectangular bounds of the matched area.

Example

local result = Screen:find("container.png")
if result then
local region = result:getRegion()
toast("Region: X=" .. region:getX() .. ", Y=" .. region:getY())
toast("Size: " .. region:getWidth() .. "x" .. region:getHeight())
-- Search within the matched region for faster matching
local innerResult = region:find("container.png")
if innerResult then
toast("Found container.png inside region!")
end
end

Fit Region Technique

getRegion() is the key method behind an important optimization pattern often called fit region.

The pattern is:

  1. Find a stable object on Screen
  2. Call getRegion() on the MatchResult
  3. Reuse that region for repeated searches inside the same object
local panel = Screen:find("reward-panel.jpg")
if panel then
local fitRegion = panel:getRegion()

-- Search only inside the fitted panel instead of the full screen
local claim = fitRegion:find("claim-button.jpg")
if claim then
fitRegion:click("claim-button.jpg")
end
end

This technique works best when the matched object always has roughly the same size. It can reduce processing cost significantly because you avoid repeating full-screen searches for every step inside the same container.