While I’ve tried to make OGT Level Manager as robust as possible there are some tweaks you may need to do while developing your game. The following techniques came about based on problems discovered by myself or other users.
Q. I’m changing k.numUnlocked but the number of unlocked levels is never changing — it stays the same.
A. It’s a feature (really)! But I got bit by this myself and spent HOURS tracking down the problem — and it turns out to be this:
OGTLM saves the number of unlocked levels in a text file that’s created when the file is first launched. That’s when it uses k.numUnlocked. After that it just grabs the number of unlocked levels from the file because if the player got past the next 10 levels you wouldn’t want them those to show up locked the next time they played the game. So it keeps track of which levels have been unlocked.
This works perfectly after your game is built for device, but it bites you during development. The way to fix it is to go to the Corona Simulator and select the File > Show Project Sandbox menu option and then drill down into that, into the Documents folder inside that, and then into the boxes folder. You’ll find a JSON file ending with .box and if you delete that and relaunch the game you’ll be able to test using whatever k.numUnlock is set to.
This is also what you need to do if you change the number of levels while developing — when that .box file is created it specifies how many levels you have. If you want to change the number of levels dynamically during your game you can (I do it in the one I’m just getting ready to release) but you have to jump through a couple hoops). See elsewhere on this page for how to do that if needed.
So ditch that .box file and you should be able to make changes while you’re testing. 🙂
Q. If the number of levels is set when the game is run for the first time, how would I add levels later? For example, I want to sell 50 more levels using in-app purchase and have them show up.
A. There’s a fairly easy way to add more levels. Here’s the code from my I. O. Silver game that does just that:
package.loaded.lm = nil lm = require("ogt_levelmanager") lm.totalLevels = NEWMAXLEVELS lm.numPages = math.ceil ( lm.totalLevels / ((lm.numCols * lm.numRows)) ) lm.init(scene.view)
After the IAP is done I run that code. It gets the OGT Level Manager out of memory (it’s in the lm variable), reloads it, sets the lm.totalLevels to the new number of levels, recalculates the number of pages to be swiped back and forth, and then calls the init function to get it started up again.
Just remember that if you’re doing anything else “special” when you first init OGT Level Manager, you need to do that again at this point. For example, in my game I’m setting a function to be run before OGTLM switches to the chosen level, and I have to set that again here after adding the new levels.
Q. How can I stop OGTLM from “downgrading” a level after it’s played again? For example, player gets 3 stars and then tries the level again, getting 2 stars — I want the 3 stars to remain since it was the highest.
A. Two ways you could handle that — before calling the function to update the stars, check to see whether the new number of stars is greater than what’s already there and if not, don’t update the stars.
Or, in the ogt_levelmanager.lua file, look for the function called k.updateStars and replace it using the code below. This new code will ONLY update the stars if the number is greater than what’s already been saved. So if you get 3 stars the first time and play it again and only get 2 stars. the original 3 stars is what will still show up. You never have to explicitly check, just pass in the number of stars and it will only update when the player gets a better score.
--============================================================== -- save numStars to lvl or k.currentLevel if left blank. function k.updateStars(numStars, lvl) local levelNum = lvl or k.currentLevel local levelInfo = GGData:new( k.dataFile ) if numStars > levelInfo.starsOnLevel[levelNum] then levelInfo.starsOnLevel[levelNum] = numStars levelInfo:save() end end