Getting Value From Text Document

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
Yoq209
What is cheating?
What is cheating?
Posts: 2
Joined: Fri Aug 19, 2022 1:00 am
Reputation: 0

Getting Value From Text Document

Post by Yoq209 »

This code allows me to send a custom value from text in a trainer to an address.

Code: Select all

Function CEButton1Click(sender)
writeInteger("Test.exe+1A234", getProperty(CETrainer_CEdit1,"Text"))
end

form_show(CETrainer)
strings_add(getAutoAttachList(), "Test.exe")
Does anybody know how could I do the same thing but send the value from text in a .txt instead of the trainer?

User avatar
LeFiXER
LeFixer
LeFixer
Posts: 478
Joined: Wed Mar 24, 2021 9:35 am
Reputation: 242

Re: Getting Value From Text Document

Post by LeFiXER »

You'll want a function that reads the file and stores the data to a table which can then be referenced within the trainer.

Code: Select all

function readFile(filename)
  local lines = {}
  if filename == nil then print('File does not exist.') return end
  local file = io.open(filename)

  for line in file:lines() do
      table.insert(lines, line)
  end
  file:close()
  return lines
end

--[[
-- Initialise a table and store the result of the function as its data.
--]]
file_table = readFile('path\\filename.extension')
In your trainer functions you can do something like:

Code: Select all

function CEButton1Click(sender)
  -- Where [1] denotes line number of the file
  local value = tonumber(file_table[1])
  writeInteger("Test.exe+1A234", value)
end
In your text document, each line should have only the value you want to read on each line.

Post Reply

Who is online

Users browsing this forum: No registered users