Search code examples
luacoronasdk

How do you update one variable in a load-save table in corona SDK


Is it possible to update one variable of a table using the load/save json saving method?I want to change one value/variable in another .lua file. How do I accomplish this?

My main.lua:

local table = {}
 table.one = "no"
 table.two = "no"
 table.three = "no"

loadsave.saveTabe(table, "trying.json", system.DocumentsDirectory)

in check.lua:

local value = loadsave.loadTable("trying.json, system.DocumentsDirectory)

   if( 5+5 == 10)then
      value.one = "yes"
     --HERE I WANT TO SAVE THE VALUE TO THE SAME JSON FILE WITHOUT CHANGING THE OTHER VALUES/VARIABLES ETC.
   end

Solution

  • Try this:

    local value = loadsave.loadTable("trying.json", system.DocumentsDirectory)
    
    if( 5+5 == 10) then
        value.one = "yes"
        loadsave.saveTable(value, "trying.json", system.DocumentsDirectory)
    end