level complete

I’m having an issue with my loading of level information when i complete a level.  when one level is complete a button becomes visible and when clicked it changes the table to make the next level unlocked. It worked for the first level and showed the first level complete unlocked, but no other levels, my codes below, can anyone see what I’m doing wrong

function levelMod(event)

if (levels[1]) then

levels[1] = 3

levels[2] = 1

composer.gotoScene(event.target arrow-10x10.png.destination,{effect=“fade”})

return true

else

composer.gotoScene(event.target.destination,{effect=“fade”})

return true

end

end

nextBtn = display.newText(“Next level”,0,0,“Helvetica”,15)

nextBtn.x=display.screenOriginX+200

nextBtn.y=display.contentHeight-5

nextBtn.destination = “gotoPlay”

nextBtn:addEventListener(“touch”,levelMod)

nextBtn.isVisible = false

sceneGroup:insert(nextBtn)

function gameOver(condition)

if(condition ==“Winner”) then

screenText.text=“Amazing!”;

nextBtn.isVisible= true

elseif(condition ==“Not Bad”) then

screenText.text=“Not To Shabby.”

nextBtn.isVisible = true

elseif (conditon ==“loser”) then

screenText.text=“You Can Do Better.”;

end

end

the gameover function is called from a different function and if winner arrow-10x10.png or not bad then the button becomes visible, then when clicked the button goes to my play file which holds my table with levels. it uses the levelMode function to unlock the levels

local levelsave = require(“levelSave”)

levels = {

1,2,2,2,2,

2,2,2,2,2,

2,2,2,2,2,

}

levels = loadInfo() 

images ={

{ getFile=“unlock.png”, types = “play” },

{ getFile=“lock .png”,types = “locked” },

{ getFile=“greenchecked.png”, types = “done” }

}

thats in the main chuck of my play file which sets the table to locked or unlocked

then

saveInfo()

is put in my show event scene.

local json = require(“json”)

function loadInfo()

local base = system.pathForFile(“levels.json”, system.DocumentsDirectory)

local jsoncontents = “”

local levelsArray = {}

local file = io.open(base,“r”)

if file then

local jsoncontents = file:read("*a")

levelsArray = json.decode(jsoncontents);

io.close(file)

return levelsArray

end

return levels

end

function saveInfo()

local base = system.pathForFile(“levels.json”, system.DocumentsDirectory)

local file = io.open(base, “w”)

local jsoncontents = json.encode(levels)

file:write(jsoncontents)

io.close(file)

end

and this is my saving and loading file.

can anyone see whats wrong and why only level one is changed

A quick tip: if you want other people to go through lots of lines of code for you, you need to make it as easy as possible for people to read your code, to have a bigger chance of someone helping.

Case in point, use the “code” button (looks like this: <> ) to open a new window to post your code, and make sure it has the proper indentation. That way your code will look like this:

local lookAtThis = code if (youFormatCodeRight = true) then it will read better end

and not like this:

local lookAtThis = code
if (youFormatCodeRight = true) then
it will read better
end

Which is visual garble, in my opinion.

function levelMod(event)

if (levels[1]) then

levels[1] = 3

levels[2] = 1

composer.gotoScene(event.target arrow-10x10.png.destination,{effect=“fade”})

return true

else

composer.gotoScene(event.target.destination,{effect=“fade”})

return true

end

end

nextBtn = display.newText(“Next level”,0,0,“Helvetica”,15)

nextBtn.x=display.screenOriginX+200

nextBtn.y=display.contentHeight-5

nextBtn.destination = “gotoPlay”

nextBtn:addEventListener(“touch”,levelMod)

nextBtn.isVisible = false

sceneGroup:insert(nextBtn)

function gameOver(condition)

if(condition ==“Winner”) then

screenText.text=“Amazing!”;

nextBtn.isVisible= true

elseif(condition ==“Not Bad”) then

screenText.text=“Not To Shabby.”

nextBtn.isVisible = true

elseif (conditon ==“loser”) then

screenText.text=“You Can Do Better.”;

end

end

the gameover function is called from a different function and if winner arrow-10x10.png or not bad then the button becomes visible, then when clicked the button goes to my play file which holds my table with levels. it uses the levelMode function to unlock the levels

local levelsave = require(“levelSave”)

levels = {

1,2,2,2,2,

2,2,2,2,2,

2,2,2,2,2,

}

levels = loadInfo() 

images ={

{ getFile=“unlock.png”, types = “play” },

{ getFile=“lock .png”,types = “locked” },

{ getFile=“greenchecked.png”, types = “done” }

}

thats in the main chuck of my play file which sets the table to locked or unlocked

then

saveInfo()

is put in my show event scene.

local json = require(“json”)

function loadInfo()

local base = system.pathForFile(“levels.json”, system.DocumentsDirectory)

local jsoncontents = “”

local levelsArray = {}

local file = io.open(base,“r”)

if file then

local jsoncontents = file:read("*a")

levelsArray = json.decode(jsoncontents);

io.close(file)

return levelsArray

end

return levels

end

function saveInfo()

local base = system.pathForFile(“levels.json”, system.DocumentsDirectory)

local file = io.open(base, “w”)

local jsoncontents = json.encode(levels)

file:write(jsoncontents)

io.close(file)

end

and this is my saving and loading file.

can anyone see whats wrong and why only level one is changed

A quick tip: if you want other people to go through lots of lines of code for you, you need to make it as easy as possible for people to read your code, to have a bigger chance of someone helping.

Case in point, use the “code” button (looks like this: <> ) to open a new window to post your code, and make sure it has the proper indentation. That way your code will look like this:

local lookAtThis = code if (youFormatCodeRight = true) then it will read better end

and not like this:

local lookAtThis = code
if (youFormatCodeRight = true) then
it will read better
end

Which is visual garble, in my opinion.