Jump to content




[LUA] Help with reading fs files.


  • You cannot reply to this topic
9 replies to this topic

#1 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 04:28 AM

I need the following program to read all the data and print it: Im not sure why its not working.
Spoiler
It wont write more than one note and once you do write more than one the view does not return any notes.

#2 D3add3d

  • Members
  • 7 posts
  • LocationSD card

Posted 02 April 2013 - 04:31 AM

Edit2: Try doing print(line) in FOR loop ending when line equals nil

Edit: derp... -_-

#3 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 04:33 AM

View PostD3add3d, on 02 April 2013 - 04:31 AM, said:

Edit: derp... -_-

Umm....

#4 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 02 April 2013 - 04:38 AM

Fs Library:
local handle = fs.open(yourFileName,"r")
local lines = handle.readLine()
for lines in handle.readLine do
 print(lines)
end
handle.close()

IO Library:
local handle = io.open("test","r")
local lines = handle:lines()
for lines in handle:lines() do
 print(lines)
end
handle:close()

EDIT: Remember to close your file handles :)

#5 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 04:41 AM

View PostSuicidalSTDz, on 02 April 2013 - 04:38 AM, said:

Fs Library:
local handle = fs.open(yourFileName,"r")
local lines = handle.readLine()
for lines in handle.readLine do
print(lines)
end

IO Library:
local handle = io.open("test","r")
local lines = handle:lines()
for lines in handle:lines() do
print(lines)
end
thank you

#6 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 02 April 2013 - 04:42 AM

It is my pleasure ^_^

#7 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 05:11 AM

View PostSuicidalSTDz, on 02 April 2013 - 04:38 AM, said:

Fs Library:
local handle = fs.open(yourFileName,"r")
local lines = handle.readLine()
for lines in handle.readLine do
print(lines)
end
handle.close()

IO Library:
local handle = io.open("test","r")
local lines = handle:lines()
for lines in handle:lines() do
print(lines)
end
handle:close()

EDIT: Remember to close your file handles :)

The view does not work. it does not print anything however just looks for another input.

#8 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 02 April 2013 - 05:22 AM

The what? Both of these script should work (You have to change the fileName of course)

EDIT: Just tested, these scripts both work flawlessly. Check the file name and make sure it exists on your computer.

#9 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 05:33 AM

It gives me a error on line 55 of the following code:

Spoiler

It's the "for handle in handle.readLine do"

#10 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 02 April 2013 - 05:40 AM

You are closing the file handle inside the for loop that uses the file contents:


handle = fs.open("myNotes/notes", "r")
lines = handle.readLine()
for lines in handle.readLine do
  print("")
  print("notes:")
  print(lines)
  handle.close()
  print("Please Re-Type Command To Continue")
end

Close it afterward


handle = fs.open("myNotes/notes", "r")
lines = handle.readLine()
for lines in handle.readLine do
  print("")
  print("notes:")
  print(lines)
  print("Please Re-Type Command To Continue")
end
handle.close()






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users