Find memory record using Lua pattern matching

A forum dedicated to use and support LUA for Cheat Engine.


Post Reply
User avatar
bbfox
Table Master
Table Master
Journeyman Hacker
Journeyman Hacker
Posts: 366
Joined: Sat Jul 23, 2022 8:59 am
Answers: 0
x 772

Find memory record using Lua pattern matching

Post by bbfox »

You can put this function into Cheat Table Lua Script.

Code: Select all

function findMemoryRecordsByPattern(pattern)
  local results = {}
  local al = getAddressList()
  local count = al:getCount()

  for i = 0, count - 1 do
    local mr = al:getMemoryRecord(i)
    if mr and mr.Description:match(pattern) then
      table.insert(results, mr)
    end
  end

  return results
end

Test sample:

Code: Select all

local matches = findMemoryRecordsByPattern("バトル:")

for _, mr in ipairs(matches) do
  print("Found record:", mr.Description)
end
Spoiler

Image

Take first data from results above:

Code: Select all

local mr = matches[1]

AA Example (change value)

Code: Select all

[ENABLE]
{$lua}
local mr = findMemoryRecordsByPattern("1st HP")[1]
if mr then mr.Value = "9999" end
{$asm}
[DISABLE]

Post Reply