Page 1 of 1

Getting Value From Text Document

Posted: Fri Aug 19, 2022 3:06 am
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?

Re: Getting Value From Text Document

Posted: Thu Aug 25, 2022 3:37 pm
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.