How do you store small data in corona without using database? You know similar to androids sharedpreferences? [import]uid: 189861 topic_id: 33648 reply_id: 333648[/import]
You could just write to text files…
There are a lot of libraries available in Code Exchange for data storing
To name a couple
1.Ice
2.Preference library
3.GGData
I wrote that Preference Library… It is very simple, so I would recommend that…
Haven’t used the other 2… [import]uid: 64174 topic_id: 33648 reply_id: 133788[/import]
Or
http://developer.coronalabs.com/code/super-simple-lua-table-save-and-load-file-functions
[import]uid: 199310 topic_id: 33648 reply_id: 133791[/import]
@Rob do i need to download the loadsave.lua? [import]uid: 189861 topic_id: 33648 reply_id: 133795[/import]
If it happens to be a table, these two functions will load and save it in permanent (sorta) storage:
[code]
json = require (“json”)
– saveTable(t,filename) saves the table t to a file in the DocumentsDirectory (named as filename)
– returns true if success, false on failure
function saveTable(t, filename)
– print(" – saving table ", 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 )
– print(" – save success.")
return true
else
print(" – save failed.")
return false
end
end
– loadTable(filename) loads in a table from filename in the DocumentsDirectory (filename)
– returns table structure (nil on error)
function loadTable(filename)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
local contents = file:read( “*a” )
local myTable = json.decode(contents)
io.close( file )
– print(" – load success.")
return myTable
end
print(" – load fail, no pre-existing file.")
return nil
end
[/code] [import]uid: 79933 topic_id: 33648 reply_id: 133798[/import]
@wwwdotphilip the way I have it coded, you would download it into a file called loadsave.lua and then put that into your project and follow the instructions in the readme for including it in your project. The code is simple enough with a little reworking you could just copy/paste them into your main.lua, but they would look more like what @mpappas posted above.
[import]uid: 199310 topic_id: 33648 reply_id: 133834[/import]
I wrote both Ice and GGData ( the latter is meant to be a replacement for the former ) so if you have any questions regarding those just shout. [import]uid: 119420 topic_id: 33648 reply_id: 133852[/import]
You could just write to text files…
There are a lot of libraries available in Code Exchange for data storing
To name a couple
1.Ice
2.Preference library
3.GGData
I wrote that Preference Library… It is very simple, so I would recommend that…
Haven’t used the other 2… [import]uid: 64174 topic_id: 33648 reply_id: 133788[/import]
Or
http://developer.coronalabs.com/code/super-simple-lua-table-save-and-load-file-functions
[import]uid: 199310 topic_id: 33648 reply_id: 133791[/import]
@Rob do i need to download the loadsave.lua? [import]uid: 189861 topic_id: 33648 reply_id: 133795[/import]
If it happens to be a table, these two functions will load and save it in permanent (sorta) storage:
[code]
json = require (“json”)
– saveTable(t,filename) saves the table t to a file in the DocumentsDirectory (named as filename)
– returns true if success, false on failure
function saveTable(t, filename)
– print(" – saving table ", 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 )
– print(" – save success.")
return true
else
print(" – save failed.")
return false
end
end
– loadTable(filename) loads in a table from filename in the DocumentsDirectory (filename)
– returns table structure (nil on error)
function loadTable(filename)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
local contents = file:read( “*a” )
local myTable = json.decode(contents)
io.close( file )
– print(" – load success.")
return myTable
end
print(" – load fail, no pre-existing file.")
return nil
end
[/code] [import]uid: 79933 topic_id: 33648 reply_id: 133798[/import]
@wwwdotphilip the way I have it coded, you would download it into a file called loadsave.lua and then put that into your project and follow the instructions in the readme for including it in your project. The code is simple enough with a little reworking you could just copy/paste them into your main.lua, but they would look more like what @mpappas posted above.
[import]uid: 199310 topic_id: 33648 reply_id: 133834[/import]
I wrote both Ice and GGData ( the latter is meant to be a replacement for the former ) so if you have any questions regarding those just shout. [import]uid: 119420 topic_id: 33648 reply_id: 133852[/import]