Posted 12 December 2014 - 11:12 PM
I don't really get the fs open
I don't really get the fs open
local f = fs.open(<filename>,<mode>)
local f = fs.open("file","w")
f.write("Write this to the file!") --replace f with whatever you declared the variable as
f.close() --CRUCIAL. Make sure you do this when you're done with
local f = fs.open("file","r")
local content = f.readAll() --Declare another variable
f.close()
print(content) --Prints content of file
local f = fs.open("file","a")
f.write("Write this right to the end of the file")
f.close()
No, you don't. If you don't close it, other programs can't access it (more or less). That's all, omitting it won't corrupt the file. Even if you don't close the file yourself, the Lua GC will take care of it eventually. But it's still good practice to do so.YOU MUST CLOSE THE FILE WHEN DONE WITH IT. If you don't, you risk corrupting the file.
Thanks for the update. I'll update the code.No, you don't. If you don't close it, other programs can't access it (more or less). That's all, omitting it won't corrupt the file. Even if you don't close the file yourself, the Lua GC will take care of it eventually. But it's still good practice to do so.YOU MUST CLOSE THE FILE WHEN DONE WITH IT. If you don't, you risk corrupting the file.
Also, please use local variables in your code. Globals can be accessed everywhere, even from other programs.
If you don't close it, nothing gets saved into the file unless you flush it.No, you don't. If you don't close it, other programs can't access it (more or less).