2088 posts
Location
South Africa
Posted 07 October 2012 - 09:03 PM
Hey really need some help here. readLine() just isnt working for me even within this simple code:
file = fs.open("derp","r")
line = file.readLine() -- tried local line = file.readLine(), also tried readAll()
file.close()
print(line)
Whats wrong? :X
Edit: forgot error: save:2: attempt to index ? (a nil value)
8543 posts
Posted 07 October 2012 - 09:50 PM
Make sure the file is being opened successfully:
file = fs.open("blah", "r")
if file then
line = file.readLine()
file.close()
end
print(line)
2088 posts
Location
South Africa
Posted 07 October 2012 - 09:59 PM
Make sure the file is being opened successfully:
file = fs.open("blah", "r")
if file then
line = file.readLine()
file.close()
end
print(line)
Ahh damn. Thank you so much :D/>/> But now it prints a blank line. In my separate file that it reads i have something written on line 1. Why?
2088 posts
Location
South Africa
Posted 07 October 2012 - 10:03 PM
Make sure the file is being opened successfully:
file = fs.open("blah", "r")
if file then
line = file.readLine()
file.close()
end
print(line)
Ahh damn. Thank you so much :D/>/> But now it prints a blank line. In my separate file that it reads i have something written on line 1. Why?
edit: Clicked quote instead of edit, sorry xD
edit: I have this code but it isn't printing … Why isn't it finding the file? I have it (Tekkit_Server_3.1.2modsComputerCraftluaromprogramscomputer) for my multiplayer server.
file = fs.open("derp", "r")
if file then
print("...")
line = file.readLine()
file.close()
end
print(line)
318 posts
Location
Somewhere on the planet called earth
Posted 07 October 2012 - 10:15 PM
The file should not be in programs folder, but in the computersfolder. –on ipod takes ages to fully explain
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 07 October 2012 - 10:16 PM
I'm having a similar problem right now. I need to read the first line of a file, which is a variable and then print that variable onto the screen.
318 posts
Location
Somewhere on the planet called earth
Posted 07 October 2012 - 10:16 PM
Cant Edith here:: ie the computers id folder ie 5 or45
8543 posts
Posted 07 October 2012 - 10:21 PM
Make sure the file is being opened successfully:
file = fs.open("blah", "r")
if file then
line = file.readLine()
file.close()
end
print(line)
Ahh damn. Thank you so much :D/>/> But now it prints a blank line. In my separate file that it reads i have something written on line 1. Why?
edit: Clicked quote instead of edit, sorry xD
edit: I have this code but it isn't printing … Why isn't it finding the file? I have it (Tekkit_Server_3.1.2modsComputerCraftluaromprogramscomputer) for my multiplayer server.
file = fs.open("derp", "r")
if file then
print("...")
line = file.readLine()
file.close()
end
print(line)
You would need to open the whole path. If it's in rom, the whole path would be something like /rom/programs/computer/file. Of course, you won't be able to write to it there (can't write to rom), but you should be able to read it fine with the correct path.
2088 posts
Location
South Africa
Posted 07 October 2012 - 10:34 PM
Sigh I just can't get this to work >_<
the exact path for the file that it reads is: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputersavedvarderp – where derp is the file which is a .txt file and still doesn't work.
file = fs.open("H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputersavedvarderp", "r")
if file then
line = file.readLine()
file.close()
end
print(line)
8543 posts
Posted 07 October 2012 - 10:45 PM
The full path, as seen by the computer, using forward slashes, not backslashes. And if it's a .txt file, you need to have the whole file name, including the .txt.
file = fs.open("/rom/programs/computer/savedvar/derp.txt", "r")
if file then
line = file.readLine()
file.close()
end
print(line)
2088 posts
Location
South Africa
Posted 07 October 2012 - 11:03 PM
Thank you so much :D/>/>