I was using this article to try to have my application remember data a user entered the last time they used the application (
After trying it out on an android and not seeing what I expected, through in a lot of “print” statements and I think the problem is that it’s not saving my table.
(note, when I say terminal below, I’m referring to the terminal for corona’s simulator)
I appreciate any help
[lua] local json = require(“json”)
function saveTable(t, filename)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local file = io.open(path, “w”)
if file then
local contents = json.encode(t)
file:write( contents )
io.close( file )
return true
else
return false
end
end
function loadTable(filename)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local contents = “”
local myTable = {}
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
local contents = file:read( “*a” )
myTable = json.decode(contents);
io.close( file )
return myTable
end
return nil
end
cacheGroup = {} [/lua]
[lua]
print (" this is Input.text "… Input.text) ------> terminal says “10”
cacheGroup.newInput = Input.text
print ("this is cacheGroup.newInput after setting equal to Input "…cacheGroup.newInput) —> terminal says “10”
saveTable(cacheGroup, “cacheGroup.json”)
print ("Input.text = "… Input.text) -----> terminal says “10”
print ("cacheGroup.currentTaxValue = " … cacheGroup.currentTaxValue) -----> terminal says “10”
cacheGroup = loadTable(“cacheGroup.json”)
print (cacheGroup.currentTaxValue) ------> terminal says “nil”
[/lua]