I have “/assets/texts/mytext.txt” in my project folder. I am trying to read the file line by line, and return a table containing the lines.
For example,
--mytext.txt
--Hello,
--World!
--to {"Hello,", "World!"}
So I wrote the code,
function ReadTxt(file_path)
local lines = {}
local file = sys.load_resource(file_path)
if file then
for line in file:gmatch("([^\n]*)\n?") do
table.insert(lines, line)
end
end
return lines
end
But when I run this,
local script = ReadTxt("/assets/texts/mytext.txt")
This error occurs.
DEBUG:SCRIPT: Error: Unable to open file at /assets/texts/mytext.txt
What’s wrong with my code? I’ve tried io.open as well, but I have no idea to reach my txt file (it means, I don’t know the directory of the file!).