Hi, i am trying to create a new file with same name of another to override id but i get error…
function unlockLevel(precLvl)
local path = system.pathForFile( “Save/Save.txt”);
local hFile = io.open(path, “r”) --Reading.
local overFile = io.open(path, “w”) --Writing Overwrite.
--local wFile, errrHnd = io.open(path, “w”);
local getNext = false;
local getLasts = false;
local countF = 0;
local lines = {};
local newLine = “”;
local restOfFile;
--local lineCt = 1;
for line in hFile:lines() do
print(“XOXOXOOXOXXO”)
if(getNext) then
for w in string.gmatch(line, “%S+”) do
countF = countF + 1;
if(countF == 4)then
newLine = newLine…“1”;
else
newLine = newLine…w…" ";
end
end
print("NUOVA LINEA ORA: "…newLine);
lines[#lines + 1] = newLine;
getNext = false;
else
if(line == precLvl) then
lines[#lines + 1] = line;
getNext = true;
else
lines[#lines + 1] = line;
end
end
end
hFile:close();
path = nil;
--hFile=nil;
for i=1,#lines do
print("xxxxxx> "…lines[i] )
end
overFile:write( “XOXOOXOXOX”)
--io.close( overFile )
overFile = nil
--local results, reason = os.remove( system.pathForFile( “Save.txt”, path ) );
--local file = io.open( path, “w” )
--file:write( lines )
--io.close( file )
--file = nil
end