Posted 06 March 2015 - 02:46 PM
I am still a bit new at computercraft and wanted to experiment with creating files. I wanted to start out by creating a program, that when run, would check the first line of a file for a number, then add one to that number and replace the number in the file. Can someone show me how to do this, I have been having trouble replacing the number. Here is what I have:
For some reason the new number is never written into the file. How do I fix this?
local r = fs.open("testFile","r")
oldNum = r.readLine(1)
oldNum = tonumber(oldNum)
print("Old: "..oldNum)
newNum = oldNum + 1
print("New: "..newNum)
fs.delete("testFile")
local w = fs.open("testFile","a")
w.writeLine(newNum)
local h = fs.open("testFile","r")
read = h.readLine(1)
if not read == nil then
print("done")
end
For some reason the new number is never written into the file. How do I fix this?
Edited on 06 March 2015 - 01:53 PM