Hi, thank you very much for the code
… but is it possible to save the levels you have unlocked, instead of the levels is locked again when reloading the app? 
thank you in advance
[import]uid: 122802 topic_id: 21095 reply_id: 84682[/import]
Hi, thank you very much for the code
… but is it possible to save the levels you have unlocked, instead of the levels is locked again when reloading the app? 
thank you in advance
[import]uid: 122802 topic_id: 21095 reply_id: 84682[/import]
You just need to add a event handler for system events and do something like this to your main.lua:
[lua]USER_SETTINGS_FILE = “user_settings.txt”
– Save off our completed and unlocked flags
function saveSettings()
local path = system.pathForFile( USER_SETTINGS_FILE, system.DocumentsDirectory )
local file = io.open( path, “w+b” )
for i=1,MAX_LEVELS do
if ( gWS.bLevelComplete[i] ) then
file:write( string.format( “Completed=%d\n”, i ) )
end
if ( not gWS.bLevelLocked[i] ) then
file:write( string.format( “Unlocked=%d\n”, i ) )
end
end
end
– Load our completed and unlocked flags
function loadSettings()
local path = system.pathForFile( USER_SETTINGS_FILE, system.DocumentsDirectory )
local file = io.open( path, “r” )
if file then
while true do
local line = file:read()
if line == nil then break end
if ( line ~= “” ) then
local nStart = string.find( line, “=” )
if ( nStart and nStart > 1 ) then
local keyStr = string.sub( line, 1, nStart - 1 )
local valStr = string.sub( line, nStart + 1 )
if ( keyStr == “Completed” ) then
gWS.bLevelComplete[tonumber( valStr )] = true
elseif ( keyStr == “Unlocked” ) then
gWS.bLevelLocked[tonumber( valStr )] = false
end
end
end
end
end
end
local function onSystemEvent( event )
if ( event.type == “applicationSuspend” or event.type == “applicationExit” ) then
saveSettings()
end
end
Runtime:addEventListener( “system”, onSystemEvent )[/lua]
[EDIT] Code above has been tested with the example app I provided.
You can download the complete Example here:
www.homebrewsoftware.com/Download/CoronaSDK/HomebrewLevelSelect_v1_11.zip [import]uid: 16734 topic_id: 21095 reply_id: 84688[/import]
Hi KenRogoway . really appreciated,
I tried this, I can go to gamelevel1.lua, gamelevel2.lua etc.
But how can I do this:
in gamelevel1.lua, when game in gamelevel1 is done, then how to get back to cScenegame.lua, in gamelevel2.lua, when game in gamelevel2 is done, then how to get back to cScenegame.lua,
how to connect those group?
Can you please give a simple example of gamelevel1.lua and gamelevel2.lua ?
I am very sorry to bother you again and again, you may say “Get Lost” to me…
Thanks a million…
Mila [import]uid: 83418 topic_id: 21095 reply_id: 84722[/import]
I don’t mind helping, but at some point you are going to have to learn LUA and the CoronaSDK enough to start writing your own code.
All you have to do when you are ready to return to cSceneLevelSelect is this:
[lua] director:changeScene( “cSceneLevelSelect”, “fade” )[/lua]
If you don’t understand that, then you aren’t going to get very far writing your app. [import]uid: 16734 topic_id: 21095 reply_id: 84724[/import]
Hi KenRogoway ,
Thanks again for your help.
Yes, I am learning Corona and lua, I just got some basic skills on this.
I have several very simple Apps on Apple App store, because very simple ones, I never used Director class and Storyboard, so I have no idea about Direct classes.
Now I am learning Director and Storyboard .
I am really appreciated for your kindness and help.
One of the great thing of Corona SDK is that there are peoples like you offering help generously.
Thanks again.
Mila
[import]uid: 83418 topic_id: 21095 reply_id: 84779[/import]
Hello Mila,
Here is a couple of links to help ya…they
should help a lot…
Good tutorial on Director…
http://www.youtube.com/watch?v=KudLE8h4kWw
A lot of Corona here…
http://learningcorona.com/
Good Luck 
Larry
[import]uid: 107633 topic_id: 21095 reply_id: 84781[/import]
No problem. I enjoy helping other people. Just want to make sure that you are also trying to learn the API.
Glad to see Larry posted the links for Director.
In the past month or so there has been a switch from Director to Storyboards. I have stayed with Director for most of my samples because a lot of people have been using that for a long time.
All of my new apps use Storyboards. It’s the API that will be supported by Ansca moving forward so that is the main reason why I’ve switched.
Ken [import]uid: 16734 topic_id: 21095 reply_id: 84785[/import]
Hi Ken, I have one last question, is it possible to reset the levels, with some code in any way? 
Thank you very much in advance [import]uid: 122802 topic_id: 21095 reply_id: 84801[/import]
Reset them? Meaning what? Reset the completed flags and locked flags?
Something simple like this should work:
[lua]-- Reset our completed and unlocked flags
function resetLevels()
for i=1,MAX_LEVELS do
gWS.bLevelComplete[i] = false
gWS.bLevelLocked[i] = true
end
– Unlock the first level
gWS.bLevelLocked[1] = false
end[/lua]
You can download the complete Example here which now includes the resetLevels() function:
www.homebrewsoftware.com/Download/CoronaSDK/HomebrewLevelSelect_v1_12.zip [import]uid: 16734 topic_id: 21095 reply_id: 84812[/import]
Hi Ken, I am sorry to bother you again. With reset I mean, when you reload the Simulator or Phone the completed levels is reset, all the levels is locked except level 1.
The code and example you posted above is certainly right, but the code dosen’t seem to work (for me) 
Thank you in advance and thank you very much for your help, I really appreciate it! [import]uid: 122802 topic_id: 21095 reply_id: 84938[/import]
I have no idea why you would want to do that, but if that is the case you can just remove the calls to saveSettings() and loadSettings(). [import]uid: 16734 topic_id: 21095 reply_id: 84940[/import]
Thank you very very much, for your help and kindness. The reason for this (reseting the levels) is I want the users (of my game) to have the ability to reset the levels if they want to 
[import]uid: 122802 topic_id: 21095 reply_id: 84968[/import]
That’s what I thought. If that is what you want to do then leave in the loadSettings() and saveSettings() calls.
Then on the button action to “reset” you just call resetLevels().
Typically this would be in your Options screen. You’d have a button to let them reset the data. Hook the button press to the resetLevels() call. [import]uid: 16734 topic_id: 21095 reply_id: 84971[/import]
–Out of Scope–
–Deleted–
[import]uid: 89165 topic_id: 21095 reply_id: 84690[/import]
KenRogoway ,
Do you have the level selection sample code implemented with storyboard and willing to share?
I can change the code from Direct class to Storyboard, but it may bring in errors, like memory leak etc.
Thanks
Mila [import]uid: 83418 topic_id: 21095 reply_id: 85293[/import]
ken, first thanks for making this avaliable. can you implement level one and two
using level1.lua and level2.lua file so that we can pick it from there. I have been trying to us this menu on my game with no luck
thanks [import]uid: 40990 topic_id: 21095 reply_id: 88743[/import]
Do you want an example using Director or Storyboards?
To change the example code just edit cLevelSelect.lua and change this:
[lua] director:changeScene( “cSceneGame”, “crossFade” )[/lua]
to this:
[lua] director:changeScene( “level”…gWS.nLevel, “crossFade” )[/lua]
Ken [import]uid: 16734 topic_id: 21095 reply_id: 88751[/import]