Read from text file and input to address
Read from text file and input to address
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?
Re: Read from text file and input to address
You want to read a file every second?
Re: Read from text file and input to address
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.
Re: Read from text file and input to address
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
Who is online
Users browsing this forum: No registered users