I need to create an in app function that only executes on the apps first run and not on subsequent runs. Any ideas? [import]uid: 51895 topic_id: 32384 reply_id: 332384[/import]
Create a sqlite database that counts the records for how many times the app has been opened. I am using this approach and it works just fine
Create the database if it doesn’t exist
require "sqlite3";
--Open and assign user database
local path = system.pathForFile("myDb.db",system.DocumentsDirectory);
db = sqlite3.open( path );
--Setup the table for userdata if it doesn't exist
local tablesetup = [[CREATE TABLE IF NOT EXISTS gamedata (id INTEGER PRIMARY KEY, STARTED INTEGER);]];
db:exec( tablesetup );
And then fill it up with the data the first time:
for row in db:nrows("SELECT max(id) as RESULT FROM gamedata") do
if not (row.RET) then
local tablesetup = "INSERT INTO gamedata (STARTED) VALUES(1);";
db:exec( tablesetup );
myVariable.started = 1;
else
for row in db:nrows("SELECT STARTED FROM gamedata") do
myVariable.started = row.PO;
end
end
end
And within your app, update the counter for every time it has been started:
local tablesetup = [[UPDATE gamedata set STARTED = STARTED+1;]];
db:exec( tablesetup );
There could be errors here, I just did a wild copy and paste from my project
Have fun!
Joakim [import]uid: 81188 topic_id: 32384 reply_id: 128799[/import]
I do something like this:
- Look and see if my settings file exists.
- If it does not, it’s a first run, set a flag to true.
- Save out my initial settings to a file (that I check in #1)
- If my firstRun flag is true, then do whatever I need to do.
[import]uid: 19626 topic_id: 32384 reply_id: 128828[/import]
Create a sqlite database that counts the records for how many times the app has been opened. I am using this approach and it works just fine
Create the database if it doesn’t exist
require "sqlite3";
--Open and assign user database
local path = system.pathForFile("myDb.db",system.DocumentsDirectory);
db = sqlite3.open( path );
--Setup the table for userdata if it doesn't exist
local tablesetup = [[CREATE TABLE IF NOT EXISTS gamedata (id INTEGER PRIMARY KEY, STARTED INTEGER);]];
db:exec( tablesetup );
And then fill it up with the data the first time:
for row in db:nrows("SELECT max(id) as RESULT FROM gamedata") do
if not (row.RET) then
local tablesetup = "INSERT INTO gamedata (STARTED) VALUES(1);";
db:exec( tablesetup );
myVariable.started = 1;
else
for row in db:nrows("SELECT STARTED FROM gamedata") do
myVariable.started = row.PO;
end
end
end
And within your app, update the counter for every time it has been started:
local tablesetup = [[UPDATE gamedata set STARTED = STARTED+1;]];
db:exec( tablesetup );
There could be errors here, I just did a wild copy and paste from my project
Have fun!
Joakim [import]uid: 81188 topic_id: 32384 reply_id: 128799[/import]
I do something like this:
- Look and see if my settings file exists.
- If it does not, it’s a first run, set a flag to true.
- Save out my initial settings to a file (that I check in #1)
- If my firstRun flag is true, then do whatever I need to do.
[import]uid: 19626 topic_id: 32384 reply_id: 128828[/import]