So this would be correct?
local fileWrite = fs.open("testVar", "w")
fileWrite.close()
local fileRead = fs.open("testVar", "r")
if fileRead then
local loadVarFromFile = fileRead.readLine()
fileRead.close()
end
print(tostring(loadVarFromFile))
fileWrite.write(read())
fileWrite.close()
Edit: Oh I see what you mean…
local fileWrite = fs.open("testVar", "w")
local fileRead = fs.open("testVar", "r")
fileRead -- does the above command that opens the file for reading
local loadVarFromFile = fileRead.readLine()
fileRead.close() -- closes the file or handle
print(tostring(loadVarFromFile))
fileWrite -- opens the file for writing
fileWrite.write(read())
fileWrite.close() -- closes the file or handle
Edit 2: Okay, so I was almost fed up with it until I decided to split the read and write into two different programs:
local fileRead = fs.open("testVar", "r")
loadTestVarFile = fileRead.readAll()
fileRead.close()
print(tostring(loadTestVarFile))
This works (finally) and I can see because the file is opened and printed correctly!
Tell me if I am right:
Line one assigns the handle AND opens the handle at the same time.
Line two assigns a local variable as the contents of all the file.
Line three closes the handle.
Line four prints the variable.
Alright! I got it to work, thanks for all the help guys!
local fileRead = fs.open("testVar", "r")
loadTestVarFile = fileRead.readAll()
fileRead.close()
print(tostring(loadTestVarFile))
local fileWrite = fs.open("testVar", "w")
fileWrite.write(read())
fileWrite.close()
Still, I would really appreciate it if someone would tell me if [[local fileRead = fs.open("testVar", "r")]] and [[local fileWrite = fs.open("testVar", "w")]] opens AND assigns the handle at the same time.