You could use rob’s loadsave.lua script found here - https://github.com/robmiracle/Simple-Table-Load-Save-Functions-for-Corona-SDK
Use that to save your current level (and later on any other things you need saved) then when your creating your level buttons you can just check if the level that goes with that button is less then, equal to or greater then your current level and set the colours accordingly.
Here is a little example of how to do that.
require("loadsave")
-- Load the lvlSettings from a .json file
local checkSettings = loadTable("lvlSettings.json")
-- if this is the first time playing we have to set lvlSettings to a value
if (checkSettings == nil) then
local defaults = {}
defaults.curLvl = 3
saveTable(defaults, "lvlSettings.json")
end
local lvlSettings = loadTable("lvlSettings.json")
-- Print out our current level
print(lvlSettings.curLvl)
--[[
Now when setting up the buttons, you just have to see if they have been played or not.
If they are less then curLvl, they have been completed (Green Button)
If they are the curLvl, they are playable (Red Button)
If they are higher then curLvl, they are locked (Blue Button)
--]]
-- example:
local lvlBtn = {}
-- create four buttons
for i = 1, 4 do
-- check to see the buttons state compared to its number and the curLvl
if i \< lvlSettings.curLvl then -- Lvl is completed
lvlBtn[i] = ui.newButton{
default = "greenBtn.png",
over = "greenBtn.png",
text = "Level: "..i,
textColor = { 0, 0, 0, 255 },
size = 12,
align = "center",
onRelease = buttonListener
}
lvlBtn[i].x = display.contentWidth/2
lvlBtn[i].y = -50 + (i\*85)
lvlBtn[i].state = "Completed"
elseif i == lvlSettings.curLvl then -- Lvl is playable
lvlBtn[i] = ui.newButton{
default = "redBtn.png",
over = "redBtn.png",
text = "Level: "..i,
textColor = { 0, 0, 0, 255 },
size = 12,
align = "center",
onRelease = buttonListener
}
lvlBtn[i].x = display.contentWidth/2
lvlBtn[i].y = -50 + (i\*85)
lvlBtn[i].state = "Playable"
else -- Lvl isn't unlocked yet
lvlBtn[i] = ui.newButton{
default = "blueBtn.png",
over = "blueBtn.png",
text = "Level: "..i,
textColor = { 0, 0, 0, 255 },
size = 12,
align = "center",
onRelease = buttonListener
}
lvlBtn[i].x = display.contentWidth/2
lvlBtn[i].y = -50 + (i\*85)
lvlBtn[i].state = "Locked"
end
end
Obviously you would need to change the button images names (or make your match it) and the y/x location of your buttons for how you want or change it to fit more of a system you use now, but this gives you the basic idea of how it can be done.
This same idea could be used with ego and ice also if you wish to use one of those rather for saving. [import]uid: 69700 topic_id: 22408 reply_id: 89340[/import]