Read info from file issue

hi i am taking info from a data.txt file, so if i read the entire document when i pass the optionLine to the bg it works but if i try to read line by line the txt document it do not work…the wired thing is that on the simulator it works perfectly but on the device display an from director only when i get the optionLine reading the file line by line

[lua]function readFile(filename)
local data;
local path = system.pathForFile( filename)
local file = io.open( path, “r” );
if file then
data = file:read( “*a” )
io.close( file )
end

return data
end
–== read by lines===----
function readFileLines(filename,number)
local data;
local path = system.pathForFile(filename)
local fh = io.open( path , “r” )
local t=1;
for line in fh:lines() do
–print(“t: “,t,” line:”,number)
if(t==number)then
data = tostring(line);
print(lines)
end
t=t+1
end
io.close( fh )
return data
end

optionLine = file.readFileLines(“data.txt”,1)

local bg = display.newImage(optionLine);
localGroup:insert(fondo);[/lua] [import]uid: 138440 topic_id: 33884 reply_id: 333884[/import]

Hello,
If this is a basic text file with strict line breaks, I would suggest using a string.gmatch for a wildcard + newLine character. This would return each line, and on match, you increment the counter until you get the proper line.

I can give you an example code bit for this if you’d like…

Brent
[import]uid: 200026 topic_id: 33884 reply_id: 134713[/import]

it would be great if you do, but let me do a little research and try some code :smiley: thanks for the idea [import]uid: 138440 topic_id: 33884 reply_id: 134747[/import]

it would be great if you do, but let me do a little research and try some code :smiley: thanks for the idea [import]uid: 138440 topic_id: 33884 reply_id: 134748[/import]

Hello,
If this is a basic text file with strict line breaks, I would suggest using a string.gmatch for a wildcard + newLine character. This would return each line, and on match, you increment the counter until you get the proper line.

I can give you an example code bit for this if you’d like…

Brent
[import]uid: 200026 topic_id: 33884 reply_id: 134713[/import]

it would be great if you do, but let me do a little research and try some code :smiley: thanks for the idea [import]uid: 138440 topic_id: 33884 reply_id: 134747[/import]

it would be great if you do, but let me do a little research and try some code :smiley: thanks for the idea [import]uid: 138440 topic_id: 33884 reply_id: 134748[/import]