So I'm trying to make a log that logs when a specific user logs into my OS. I can make it write fine but it seems to throw an error no matter what I do when I perform a readAll().
I can't find much info in the tutorial and wiki about using readAll().
Here is my code:
if fs.exists("log") then
local h = fs.open("log", "a") -- should I be using read or write mode?
loglen=textutils.unserialize(h.readAll()) --error is for this line, with or without unserialize, it throws "Attempt to index ? a nil value"
print(loglen) --debugging
if string.len(loglen)>30 then --if the length of the file is X bits, delete and recreate to clear all
h.close()
fs.delete("log")
end
h.close() -force close to prevent loss of data. not needed
local h = fs.open("log", "a") --open to add new log
h.write(userName.." - Day: "..os.day().." | Time: "..os.time()..". \n") --userName is derived above this function
h.close()
end
It seems like no matter what I try, I still get an error relating to a nil value. I have forced data into the file and it's still nil. Is it because I am amending the file rather than opening in write or read mode?
Edited by Kizz, 02 April 2015 - 12:53 PM.












