Posted 07 April 2013 - 07:36 AM
Hello :P
So.. I'm writing a script that needs to save different tables on a file and read from them and i'm still noob with coding, so i need a little help.
This is not all the script, it's only the part i have problems with, anyway i wrote this:
I wanted to make the function more generic though, to be able to use it with other files and tables so I wrote this:
And this doesn't work, it's gonna print an empty table.
Anyone can explain me why? I know it's something related to the "tavola" argument I added.
Thank you :D
So.. I'm writing a script that needs to save different tables on a file and read from them and i'm still noob with coding, so i need a little help.
This is not all the script, it's only the part i have problems with, anyway i wrote this:
inveData = {}
function readfile()
h = fs.open("id.txt","r")
unser = h.readAll()
inveData = textutils.unserialize(unser)
h.close()
end
readfile()
for k,v in pairs(invedata) do
print(k.." "..v)
end
and it works fine. In the file i got a serialized table for testing porpuse, and it prints it like it should do.I wanted to make the function more generic though, to be able to use it with other files and tables so I wrote this:
inveData = {}
function readfile(filez,tavola)
h = fs.open(filez,"r")
unser = h.readAll()
tavola = textutils.unserialize(unser)
h.close()
end
readfile("id.txt",inveData)
for k,v in pairs(invedata) do
print(k.." "..v)
end
And this doesn't work, it's gonna print an empty table.
Anyone can explain me why? I know it's something related to the "tavola" argument I added.
Thank you :D