I am making a highscore saving function. Is there a way to see if the file exits. I want to see if the file is nil and then make it 0 (if it is the first time playing). What am I doing wrong. It always gives me an error saying that
function highscore() local filepath = system.pathForFile("highscoresave.txt", system.DocumentsDirectory) file1 = io.open(filepath,"r") if file1 == nil then io.close(file1) file3 = io.open(filepath,"w") file3:write("0") io.close(file3) end file = io.open(filepath,"r") if scoreNum \> file:read("\*n") then io.close(file) file2 = io.open (filepath,"w") file2:write (scoreNum) io.close(file2) end --file:read("\*n") --lhs = display.newText(saveData,0,0) fileR = io.open(filepath,"r") data = fileR:read("\*a") print (data) lhs = display.newText(data,240,410) io.close (fileR) end