I do not know how to lock the future levels of my game until the user beats the current unlocked level.
For instance, the user cannot play level 2 until they beat level 1. [import]uid: 32061 topic_id: 6322 reply_id: 306322[/import]
I do not know how to lock the future levels of my game until the user beats the current unlocked level.
For instance, the user cannot play level 2 until they beat level 1. [import]uid: 32061 topic_id: 6322 reply_id: 306322[/import]
Any ideas??? [import]uid: 32061 topic_id: 6322 reply_id: 21974[/import]
Hi 4d32petersc!
In the game i’m working for (sorry for my poor english!), i’m going to use files to save the level that is currently unlocked, and use some logic to lock the rest of the levels.
I have not written the code, so i only can tell you how it works in my mind:
I have assigned a number to every level, and i will save the LAST level played (or unlocked) in a file, and when i am in “select level” screen, i open the file that saves the last level number, and use a conditional function for every levels, something like:
if lastLevelUnlocked == levelNumber then
levelPlayable=true
elseif lastLeveunlocked \> levelNumber then
levelPlayable=true
elseif lastLevelUnlocked \< levelNumber then
levelPlayable=false
end
Using something like this, the current level (not completed, but unlocked) and the levels behind the current are unlocked (playable), and the rest of the levels are locked.
NOTE that this is not real code, is just a simple example of the logic i’m going to use to determine what levels are playable and what are locked.
I hope this can help you, and if you find a better way to do this, please let me know! [import]uid: 14235 topic_id: 6322 reply_id: 21989[/import]
That is very helpful. How you are going to store when a level has been beaten? and then how do you reference that in the select level screen?
Thanks again! I look forward to seeing what you come up with. If I can figure it out I will post it.
[import]uid: 32061 topic_id: 6322 reply_id: 22032[/import]
[lua]-- this might help
gameLevel = --load level from file
disabledButton = display.newImage(“disabled.png”)
if gameLevel => 1 then
level1Button = display.newImage(“level1.png”)
else
disabledButton
end
if gameLevel => 2 then
level2Button = display.newImage(“level2.png”)
else
disabledButton
end
– at the end of the completed level update the gameLevel file with the next level number.
[lua] [import]uid: 33866 topic_id: 6322 reply_id: 22462[/import]
The problem I am having is how the game will recognize when to lock or unlock a level. For instance, can I do an if then and say if an even happens, the next level == unlocked? [import]uid: 32061 topic_id: 6322 reply_id: 22627[/import]
When level 1 is completed you have some event already; like a function displaying a message of “Well done” or something like that, right? Or maybe changing to level 2 automatically?
Within that function is where you’d state the the next level was unlocked.
There is a tutorial up in the sample code section for saving data, I imagine you’d want to use that so the app remembers where the player was up to each time it’s launched
[import]uid: 10144 topic_id: 6322 reply_id: 22635[/import]
I did some research and I’ve come up with the facts that
I need to have a data file that holds the levels and saves whether or not the prior level has been beaten, thus unlocking the next level.
Somehow I need to reference that data file and tell it if a level has been beaten
I need to reference that data file again to tell the game to allow the user to play certain levels.
My only problem now is not knowing how to do that. Thanks for any help you can provide. [import]uid: 32061 topic_id: 6322 reply_id: 22640[/import]
Did you look at the Save Data project in the code exchange? That does all those things. [import]uid: 10144 topic_id: 6322 reply_id: 22655[/import]
You can try to use bebeeclass from code exchange [import]uid: 11749 topic_id: 6322 reply_id: 22670[/import]
Peach - I did look into that, are you referring to the safe table? http://developer.anscamobile.com/content/save-table My problem is that I don’t see any type of code referencing levels so it’s hard to dissect it and learn. Is there code out there or at least a sample game that has locked levels?
From the code above, which screen does it go into? And what code needs to go into the data.txt file? [import]uid: 32061 topic_id: 6322 reply_id: 22833[/import]
I am going down the path of creating global variables to store whether or not the level is locked.
Will the global variable save when the game is closed? or will they reset to their original values? If they do reset, how do make main.lua save?
I need help on a basic function. I want the logo of the level to be a lock if it is locked. How do I make that happen and what type of function do I need to make the if/then work? Here is what I have so far.
if \_G["level2"] = 0 then
local bt02 =display.newImage("images/lock.png")
else
local bt02 = display.newImage("images/bombLevel2.png")
[import]uid: 32061 topic_id: 6322 reply_id: 24678[/import]
are there any games out there in the code exchange that have this I can sample? If not, it would be a big help if someone who knew how to do this posted a very simple example. [import]uid: 32061 topic_id: 6322 reply_id: 28442[/import]