Saving a Single Item in JSON

I’m using Rob Miracles easy save load into JSON code.

I have a couple of layers in the table.    I have the high level and then a sub table for each level.

I have items in the high level as follows:

currentgameScore

highestgameScore

nextLevel

currentLevel

unlockedLevels

The problem is, when I try to save a single item such as current game score, I keep overwriting the entire table.  I’ve tried some of the following in an attempt to get it to work…along with various others.


myData.settings = loadsave.loadTable(“settings.json”)

  myData.settings = {}

   myData.settings.currentgameScore = 777

   myData.settings.unlockedLevels = myData.settings.unlockedLevels

    myData.settings.currentLevel = myData.settings.currentLevel

   myData.settings.nextLevel = myData.settings.nextLevel

   myData.settings.highestLevel = myData.settings.highestLevel

loadsave.saveTable(myData.settings,“settings.json”)


myData.settings = loadsave.loadTable(“settings.json”)

  myData.settings = {}

   myData.settings.currentgameScore = 777

    

loadsave.saveTable(myData.settings,“settings.json”)


I would really appreciate it if someone could tell me what I am doing wrong.

Thanks,

Lori

Hey, lgalcott,

It looks like you are grabbing the table:

[lua]

myData.settings = loadsave.loadTable(“settings.json”)

[/lua]

Then completely erasing it, and starting over with a clean table with this:

[lua]

myData.settings = {}

[/lua]

Try commenting out just that  line, and see how it works:

[lua]

– myData.settings = {}

[/lua]

WOW…thanks.   that seemed to work!

Hey, lgalcott,

It looks like you are grabbing the table:

[lua]

myData.settings = loadsave.loadTable(“settings.json”)

[/lua]

Then completely erasing it, and starting over with a clean table with this:

[lua]

myData.settings = {}

[/lua]

Try commenting out just that  line, and see how it works:

[lua]

– myData.settings = {}

[/lua]

WOW…thanks.   that seemed to work!