I tried io.open(path,“w”) but it says i have no file called like this, but its obvious i want to create it. How could i do it? Thank you guys for help
Could you print the code you’re using to write and close to the file as well?
I have already resolved 1 minute ago i m sorry for wasting your time. Have a nice day!
local json = require “json”
function loadTable(filename)
--print(filename)
local path = system.pathForFile( filename, system.DocumentsDirectory )
local fh, reason = io.open( path, “r” )
if fh then
– read all contents of file into a string
local contents = fh:read( “*a” )
print( "Contents of " … path … “\n” … contents )
local jsonRead = json.decode(contents)
return jsonRead
else
print( "Reason open failed: " … reason ) – display failure message in terminal
end
end
function saveTable(myGameSettings,filename)
local saveGame = {}
local jsonSaveGame = json.encode(myGameSettings)
local path = system.pathForFile( filename, system.DocumentsDirectory )
local file = io.open( path, “w” )
file:write( jsonSaveGame )
io.close( file )
file = nil
end
Could you print the code you’re using to write and close to the file as well?
I have already resolved 1 minute ago i m sorry for wasting your time. Have a nice day!
local json = require “json”
function loadTable(filename)
--print(filename)
local path = system.pathForFile( filename, system.DocumentsDirectory )
local fh, reason = io.open( path, “r” )
if fh then
– read all contents of file into a string
local contents = fh:read( “*a” )
print( "Contents of " … path … “\n” … contents )
local jsonRead = json.decode(contents)
return jsonRead
else
print( "Reason open failed: " … reason ) – display failure message in terminal
end
end
function saveTable(myGameSettings,filename)
local saveGame = {}
local jsonSaveGame = json.encode(myGameSettings)
local path = system.pathForFile( filename, system.DocumentsDirectory )
local file = io.open( path, “w” )
file:write( jsonSaveGame )
io.close( file )
file = nil
end