Hi!
I’m trying to read data from a file, a .txt. This file has several lines, each one with a color, like:
blue
red
green
I’m trying to read it with io:lines(), but it only reads one line. This is my code:
nomFitxer = ("pantalles/" .. numNivell .. ".txt")
ruta = system.pathForFile( nomFitxer, system.ResourceDirectory )
local fitxer = io.open( ruta, "r" )
if fitxer then -- nil if no file found
for line in fitxer:lines() do
print(index .. ": " .. line)
arrayColores.insert(index, line)
index = index + 1
end
else
print("File not found")
end
Of course, I want to read all the lines in the file and insert them in arrayColores table. Any guess why it isn’t working?
Thanks!
Hector [import]uid: 36639 topic_id: 8298 reply_id: 308298[/import]