Read from text file and input to address

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
iosufdhgd
What is cheating?
What is cheating?
Posts: 3
Joined: Sun Jun 05, 2022 1:28 pm
Reputation: 0

Read from text file and input to address

Post by iosufdhgd »

Looking for a script that reads from a text file, and inputs each line in said text file to a certain address every second or so. Does anything know how to do that?

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

Re: Read from text file and input to address

Post by LeFiXER »

You want to read a file every second?

iosufdhgd
What is cheating?
What is cheating?
Posts: 3
Joined: Sun Jun 05, 2022 1:28 pm
Reputation: 0

Re: Read from text file and input to address

Post by iosufdhgd »

LeFiXER wrote:
Mon Jun 06, 2022 1:58 pm
You want to read a file every second?
same file, just a new line. also, yeah, new line every second would be optimal

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

Re: Read from text file and input to address

Post by LeFiXER »

You could get the linecount of the file and iterate through the file based on the linecount then update the address according to the position of the loop.

Yoq209
What is cheating?
What is cheating?
Posts: 2
Joined: Fri Aug 19, 2022 1:00 am
Reputation: 0

Re: Read from text file and input to address

Post by Yoq209 »

LeFiXER wrote:
Mon Jun 06, 2022 3:08 pm
You could get the linecount of the file and iterate through the file based on the linecount then update the address according to the position of the loop.
Could you possibly make an example script doing this? I want to apply values from text in a txt.

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

Re: Read from text file and input to address

Post by LeFiXER »

Yoq209 wrote:
Fri Aug 19, 2022 1:17 am
Could you possibly make an example script doing this? I want to apply values from text in a txt.
It's a relatively trivial task to loop through a file and output the results, nevertheless, I have written a function and provided code on how you can store the data of each line in a table, iterate over that table, and then print the results to the output window:

Code: Select all

function readFile(filename)
  local lines = {}
  -- if file doesn't exist then just return nil because we don't want to proceed
  if filename == nil then return end
  -- open a handle to the file
  local file = io.open(filename)

  -- loop through the file line-by-line
  for line in file:lines() do
      -- Insert the line into the table
      table.insert(lines, line)
  end
  -- close the handle to the file
  file:close()
  return lines
end

-- Initialise a table and store the result of the function as its data
local file_table = readFile('C:\\data.txt')

-- loop through the table and print to Output window
for k,v in pairs(file_table) do
    if v ~= nil then
       print(v)
    end
end

Post Reply

Who is online

Users browsing this forum: No registered users