save preferences high score

I have an old loadsave with module( …, package.seeall )

It is deprecated

I would like to update it

This is the old code. It works with the old loadsave.

I replaced the old with the new and it does not  work.

I use this new library.

https://github.com/robmiracle/Simple-Table-Load-Save-Functions-for-Corona-SDK

I get this log

*******************************************************************

main.lua58: attemp to call field ‘fileExists’(a nil value)

stack traceback:

       main.lua:58 in main chunk

Do you want to relaunch the project?

*********************************************************************

I dont know how to update the code.

I get this log

main.lua

[lua]

local myGlobalData = require( “globalData” )

local loadsave = require(“loadsave”) -

_G.saveDataTable = {} – Define the Save/Load base Table to hold our data

storyboard.purgeOnSceneChange = true

– Load in the saved data to our game table

–check the files exists before !

if loadsave.fileExists(“dba_vc_template_data.json”, system.DocumentsDirectory) then

saveDataTable = loadsave.loadTable(“dba_vc_template_data.json”)

else

saveDataTable.highScore = 0

– Save the NEW json file, for referencing later…

loadsave.saveTable(saveDataTable, “dba_vc_template_data.json”)

end

saveDataTable.highScore = 0

–Now load in the Data

saveDataTable = loadsave.loadTable(“dba_vc_template_data.json”)

myGlobalData.highScore = saveDataTable.highScore

myGlobalData.gameScore = 0

[/lua]

Where did you get information that there was a .fileExists() method?  I may have removed it recently when I was cleaning up the library from where someone else had submitted some changes that were causing problems.

You don’t need to know if the fileExists or not, simply do:

mySettings = loadsave.loadTable(“yourtable.json”)

if mySettings == nil then

   – do stuff because the file DOES NOT exist

else

   – do stuff because the file DOES exist

end

The fileExists function was just opening the file for read and closing it just to let you know that it exists.  The existing loadTable() funciton returns nil if the table doesn’t exist, or the table if it does, so you really don’t need to test for its existence.

Rob

Where did you get information that there was a .fileExists() method?  I may have removed it recently when I was cleaning up the library from where someone else had submitted some changes that were causing problems.

You don’t need to know if the fileExists or not, simply do:

mySettings = loadsave.loadTable(“yourtable.json”)

if mySettings == nil then

   – do stuff because the file DOES NOT exist

else

   – do stuff because the file DOES exist

end

The fileExists function was just opening the file for read and closing it just to let you know that it exists.  The existing loadTable() funciton returns nil if the table doesn’t exist, or the table if it does, so you really don’t need to test for its existence.

Rob