Created
November 28, 2012 06:30
-
-
Save cjanis/4159408 to your computer and use it in GitHub Desktop.
Data Storage with Corona SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--os.remove(system.pathForFile( "data.db", system.DocumentsDirectory)) | |
-- read data | |
function readData() | |
local path = system.pathForFile("data.db", system.DocumentsDirectory) | |
local file = io.open(path, "r") | |
if (file) then | |
data = json.decode(file:read("*a")) | |
else | |
file = io.open(path, "w") | |
file:write("{ \"visits\": 0, \"rated\": \"no\", \"iap\": { \"iapBalloons\": \"no\" } }") | |
data = { visits = 0, rated = "no", iap = { iapBalloons = "no" } } | |
end | |
io.close(file) | |
end | |
readData() | |
-- write data | |
function writeData() | |
os.remove(system.pathForFile( "data.db", system.DocumentsDirectory)) | |
local path = system.pathForFile("data.db", system.DocumentsDirectory) | |
local file = io.open(path, "w") | |
file:write("{ \"visits\": ", data.visits ,", \"rated\": \"", data.rated ,"\", \"iap\": { \"iapBalloons\": \"", data.iap.iapBalloons ,"\" } }") | |
io.close(file) | |
readData() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment