Tweaking the variables at the top of the ogt_levelmanager.lua file is half of using the library. The other half is taking advantage of the utility functions available for you.
In the following examples I will assume you’ve done this at the top of your code:
local lm = require("ogt_levelmanager")
Then when I show how a function is called I’ll do it like this:
Also, in most functions where you can pass in a level number that parameter is optional. If you don’t pass it in, the function will use the currently set level. Just remember that so I don’t have to repeat it a dozen times. 😉 Basically, if I say that a parameter is optional, that’s because it will automatically default to whatever is currently being used.
Turn Audio On/Off
Pass true or false in to enable or disable the sound effects that are available when the player clicks the level select image or the next and previous buttons (if sound effects have been set).
Save a Score
Example: lm.updateScore(score, lvlNum)
Pass in the score and the level number (optional) to save that score.
Load a Score
Example: local myScore = lm.getLevelScore(lvlNum)
Retrieve the saved score for a specific level (lvlNum is optional).
Example: lm.updateUserName(uname, dataFile)
Save the specified username (required) to the chosen dataFile (optional).
Example: local currUser = lm.getUserName(dataFile)
Retrieve the username for the specified data file (optional).
Save Number of Stars
Example: lm.updateStars(numStars, lvlNum)
Save the number of stars (required) earned on the chosen level (optional).
Load Number of Stars
Example: local starsEarned = lm.getLevelStars(lvlNum)
Retrieve the number of stars earned on the specified level (optional).
Lock/Unlock a Level
Example: lm.updateLock(true|false, lvlNum)
Pass in true or false to answer the question, “Is level lvlNum locked?” So true means it’s locked, while passing in false means it’s unlocked.
While lvlNum is optional, it’s a little different than most — if you leave that blank it will not unlock or lock the current level, but the next level.
Unlock the Next Level
This is just a shortcut function that you’d use in many cases instead of the previous one. When a user is playing and you want the next level unlocked, use this function and don’t worry about passing true, false, or anything else.
Get Lock Status
Example: local levelIsLocked = lm.getLockStatus(lvlNum)
Pass in a level number and it will return a boolean value telling you whether the specified level is locked (true) or not (false).
While the level number parameter is technically optional, this is one function where you’ll probably almost always specify the level.
Is There Another Level
Example: local canKeepPlaying = lm.anotherLevel(lvlNum)
Check to see whether there’s another level after the one specified (optional). Returns true if there’s another level or false if the level number passed in (or the current level) is the last one.
Go To Next Level
This will launch the level after the level number (optional) that’s passed in (the next level).
This function ONLY works on sequential or named levels. It does not work when you use the same storyboard scene for all levels (k.playScene = “foo”).
Reset All Levels
Use this to reset the specified data file (optional) — all scores to 0, all stars earned to 0, and lock all levels except for the number specified in k.numUnlocked. Does not change the username in the data file.
Back to OGTLM Dashboard