Page 1 of 1

Find memory record using Lua pattern matching

Posted: Sat Aug 20, 2022 9:12 pm
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]