Hi,
Have a little code here. Its unlocks Characters, set selected character as a main and automatically unselect previous one when new one are selected or unlocked. This is just for visual look, when it comes to save and load (with JSON) it’s not what you want to have.
In really It’s pretty common thing in games, so how do you guys manage things like that?
Create tables which holds any of those separate, set visible, replace, remove from table, how to manage those?
local buttonY = 50 local unlockChar = {} local secelctedChar = {} local select\_unselectChar = {} local secelctedCharTable = {} local unsecelctedCharTable = {} for i = 1, 6 do local function manage(event) display.remove(unlockChar[i]) unlockChar[i] = nil table.insert(secelctedCharTable, 1, secelctedChar[i]) table.remove(secelctedCharTable, 3) secelctedCharTable[1].isVisible = true secelctedCharTable[2].isVisible = false table.insert(unsecelctedCharTable, 1, select\_unselectChar[i]) table.remove(unsecelctedCharTable, 3) unsecelctedCharTable[2].isVisible = true unsecelctedCharTable[1].isVisible = false mainCharacter:removeSelf() mainCharacter = nil mainCharacter = display.newImage("image"..i..".png", 200, 200) end unlockChar[i] = display.newRect(60, buttonY, 40, 40) unlockChar[1].isVisible = false unlockChar[i]:addEventListener("tap", manage) secelctedChar[i] = display.newImage("image"..i..".png", 60, buttonY) secelctedChar[i].isVisible = false secelctedChar[1].isVisible = true select\_unselectChar[i] = display.newImage("image"..i..".png", 60, buttonY) select\_unselectChar[i].alpha = 0.2 select\_unselectChar[i].isVisible = false select\_unselectChar[i]:addEventListener("tap", manage) buttonY = buttonY+70 end table.insert(secelctedCharTable, secelctedChar[1]) table.insert(unsecelctedCharTable, select\_unselectChar[1]) mainCharacter = display.newImage("image1.png", 200, 200)