3057 posts
Location
United States of America
Posted 10 April 2014 - 02:44 AM
This page (
http://computercraft.info/wiki/Tables#Saving_Tables_to_Files) is incorrect, at least in CC1.6. It states this line:
local data = file.readAll()
which gives me a 'nil' error. It should be this:
local data = file.read()
At least, as far as I know.
7508 posts
Location
Australia
Posted 10 April 2014 - 03:08 AM
nope. readAll is fine.
I'm going to assume the error message is attempt to index ? (a nil value)
which means the file you're trying to read doesn't exist.
1847 posts
Location
/home/dannysmc95
Posted 11 April 2014 - 09:21 PM
One of the things I found out with CC1.6+ If you try the following:
local file = fs.open("data", "r")
local file = file.readAll()
Will error saying attempt to index global and moan at you!
If you take away the local bit so it looks like this:
file = fs.open("data", "r")
file = file.readAll()
It should work! Well it did when I just tested it!
1220 posts
Location
Earth orbit
Posted 11 April 2014 - 09:33 PM
One of the things I found out with CC1.6+ If you try the following:
local file = fs.open("data", "r")
local file = file.readAll()
Will error saying attempt to index global and moan at you!
If you take away the local bit so it looks like this:
file = fs.open("data", "r")
file = file.readAll()
It should work! Well it did when I just tested it!
That's strange. I use 'local file = fs.open("fileName","r")' in CC1.6 without problems. Sounds like something else is going on there, DannySMc.
7508 posts
Location
Australia
Posted 12 April 2014 - 02:00 AM
One of the things I found out with CC1.6+ If you try the following:
local file = fs.open("data", "r")
local file = file.readAll()
Will error saying attempt to index global and moan at you!
If you take away the local bit so it looks like this:
file = fs.open("data", "r")
file = file.readAll()
It should work! Well it did when I just tested it!
yeh as Dog said, you've definitely got something wrong somewhere else, removing local is never a solution, and the first code — although it has a redundant `local` — works perfectly fine.
local file = fs.open("data", 'r')
file = file.readAll() --# its still local here, 'cause you defined it local above
1847 posts
Location
/home/dannysmc95
Posted 12 April 2014 - 04:30 PM
One of the things I found out with CC1.6+ If you try the following:
local file = fs.open("data", "r")
local file = file.readAll()
Will error saying attempt to index global and moan at you!
If you take away the local bit so it looks like this:
file = fs.open("data", "r")
file = file.readAll()
It should work! Well it did when I just tested it!
yeh as Dog said, you've definitely got something wrong somewhere else, removing local is never a solution, and the first code — although it has a redundant `local` — works perfectly fine.
local file = fs.open("data", 'r')
file = file.readAll() --# its still local here, 'cause you defined it local above
Ahh fair enough, I have no idea then >.<