Hi Guys!
I’ve been using this code for saving level progresses i made in the game
[lua]
local json = require( “json”)
local filename = “data.json”
function save()
local value = {coins = M.coins , categories = M.categories, timeStamp = M.timeStamp}
local path = system.pathForFile( filename, system.DocumentsDirectory )
local file = io.open(path, “w”)
if ( file ) then
local contents =json.encode(value)
file:write( contents )
io.close( file )
return true
else
print( "Error: could not read ",filename, “.” )
return false
end
end
function load()
local path = system.pathForFile( filename, system.DocumentsDirectory )
local contents = “”
local file = io.open( path, “r” )
if ( file ) then
local contents = file:read( “*a” )
local value = json.decode( contents)
io.close( file )
return value
else
end
return nil
end
[/lua]
What should i do to create a function which “Reset Progress” in my “New Game” button
and
What should i also do to create a function which is a “Continue”, this will lead the player to the progress he/she did before he/she left/exited the game?
Example:
New Game > Level 1 > Finished Level > Level 2 > Leave/Exited > Continue > Level 2 (exact scene/progress the player was before he/she leave/exited the game) > Finished Level > Level 3 > Return to menu > New Game > “Reset Progress?” > Level 1
I hope my example is ok, and Thank you very much in advance for the help :lol: