android - How to create and save settings in corona sdk? -


i using method save settings game

http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

when should use savetabel , loadtable

if use savetable when app starts saves default valeus of table, how can load last saved valeus when app starts again.

can use( if )to check whether file exist or not ?

some please

thanks in advance!

you should load file default values , if file doesn't exist should create it. , every time change value save value in file.

following code may you:

   function load_settings()       local path = system.pathforfile( "savesettings.json", system.documentsdirectory )       local file = io.open( path, "r" )       if file           local savedata = file:read( "*a" )           io.close( file )            local jsonread = json.decode(savedata)           value = jsonread.value       else           value = 1      end end  function save_settings()    local savegame = {}      if value     savegame["value"] = value      end       local jsonsavegame = json.encode(savegame)       local path = system.pathforfile( "savesettings.json", system.documentsdirectory )      local file = io.open( path, "w" )       file:write( jsonsavegame )      io.close( file )     file = nil end 

just call these functions loading , saving data. , easier if code these functions in different file , every time of loading , saving require file , use these functions.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -