Posted 03 June 2015 - 01:19 AM
I am trying to iterate through all the lines in a file and return a table containing the text from each line, in order.
function getNotes()
local f = fs.open("example", "r")
local end_reached = false
local notes = {}
while not end_reached do
local current_note = f.readline()
if current_note ~= nil then
notes.insert(current_note)
else
end_reached = true
end
end
f.close()
return notes
end
print(textutils.serialize(getNotes()))
However, this gives an attempt to call nil error on line 6, and I see nothing wrong with doing f.readline(). Please tell me if there is a proper way to read all the lines of a file.