How to increment an index value everytime the application is launched

Hello,

I want to have an index variable in my application that is incremented everytime the application is launched.
for example, initially it is 0. The first time the application is run it changes to 1, the 2nd time it changes to 2 and so on…

How can i do that?

Thanks [import]uid: 175611 topic_id: 33980 reply_id: 333980[/import]

Check out this bit of code from Rob Miracle:

http://developer.coronalabs.com/code/super-simple-lua-table-save-and-load-file-functions

Store this in a local table (I call mine dataAccess).Then, in main, setup something that tests if the json file exists and creates a new one if it isn’t. This new file will persist between launches.

[lua] local dataAccess = require(“loadsave”)
local gameData = dataAccess.loadTable( “gameData.json” )
local setupGameData = function()
gameData.isFirstLaunch = true
gameData.numLaunches = 1
end

if not gameData then
gameData = {}
setupGameData()
dataAccess.saveTable( gameData, “gameData.json” )
end[/lua]

Every time you need to check the number of launches, load up the table and see. Just be sure to use the saveTable function after you change it.

-Treb
[import]uid: 181948 topic_id: 33980 reply_id: 135085[/import]

Thanks, actually the reason I want to keep track of the launch counter is that everytime the game is launched I want to create a new folder who’s name has the index of the launch number. like Session1, Session2 and so on, then i’m saving files in this folder.

I was trying to avoid using xml and json…

The solution ou gave, would it help me in naming the folders in the way i stated?

[import]uid: 175611 topic_id: 33980 reply_id: 135087[/import]

You could also use GGData for this - https://github.com/GlitchGames/GGData [import]uid: 119420 topic_id: 33980 reply_id: 135125[/import]

Check out this bit of code from Rob Miracle:

http://developer.coronalabs.com/code/super-simple-lua-table-save-and-load-file-functions

Store this in a local table (I call mine dataAccess).Then, in main, setup something that tests if the json file exists and creates a new one if it isn’t. This new file will persist between launches.

[lua] local dataAccess = require(“loadsave”)
local gameData = dataAccess.loadTable( “gameData.json” )
local setupGameData = function()
gameData.isFirstLaunch = true
gameData.numLaunches = 1
end

if not gameData then
gameData = {}
setupGameData()
dataAccess.saveTable( gameData, “gameData.json” )
end[/lua]

Every time you need to check the number of launches, load up the table and see. Just be sure to use the saveTable function after you change it.

-Treb
[import]uid: 181948 topic_id: 33980 reply_id: 135085[/import]

Thanks, actually the reason I want to keep track of the launch counter is that everytime the game is launched I want to create a new folder who’s name has the index of the launch number. like Session1, Session2 and so on, then i’m saving files in this folder.

I was trying to avoid using xml and json…

The solution ou gave, would it help me in naming the folders in the way i stated?

[import]uid: 175611 topic_id: 33980 reply_id: 135087[/import]

You could also use GGData for this - https://github.com/GlitchGames/GGData [import]uid: 119420 topic_id: 33980 reply_id: 135125[/import]