Posted 05 November 2014 - 06:20 PM
I'm having some trouble with some code that I'm writing for my benefit to learn how to use the fs api a little better. Right now, what the program is trying to accomplish is to look at a file and store what's on it in a variable that I can print. Right now, I'm having some trouble with the fs.readLine() function not wanting to go through, and I can't seem to see why. I've looked at the common errors and such, but cannot seem to find why the function doesn't want to go through. So, please, help me if anyone can.
rAccessNum = {}
accessNum = fs.open("/common/test/accessNumb", "w")
accNumData = fs.open("/common/test/accessNum", "r")
if fs.exists("/common/test/") == false then
fs.makeDir("/common/test/")
end
if fs.exists("/common/test/accessNumb") == false then
accessNum()
accessNum.close()
end
line = accNumData.readLine()
repeat
table.insert(rAccessNum, line)
line = accNumData.readLine()
until line == nil
accNumData.close()
realAccNum = rAccessNum[1]
if realAccNum == nil then
realAccNum = 0
end
realAccNum = realAccNum + 1
print("You've opened this file "..realAccNum.." times!")
accessNum.write(realAccNum)
accessNum.close()