Hi, Im using this for saving and loading :
local saveValue = function( strFilename, strValue )
-- will save specified value to specified file
local theFile = strFilename
local theValue = strValue
local path = system.pathForFile( theFile, system.DocumentsDirectory )
-- io.open opens a file at path. returns nil if no file found
local file = io.open( path, "w+" )
if file then
-- write game score to the text file
file:write( theValue )
io.close( file )
end
end
local loadValue = function( strFilename )
-- will load specified file, or create new file if it doesn't exist
local theFile = strFilename
local path = system.pathForFile( theFile, system.DocumentsDirectory )
-- io.open opens a file at path. returns nil if no file found
local file = io.open( path, "r" )
if file then
-- read all contents of file into a string
local contents = file:read( "\*a" )
io.close( file )
return contents
else
-- create file b/c it doesn't exist yet
file = io.open( path, "w" )
file:write( "0" )
io.close( file )
return "0"
end
end
Im using director class and in my main.lua I have this:
local loadunlock = function()
\_G.levelunlock = loadValue( "levelunlock.data" );
end
loadunlock();
When I complete level I unlock next level:
if \_G.levelunlock == 1 then
\_G.levelunlock = 2
saveValue("levelunlock.data", tonumber(\_G.levelunlock))
end
And then in level select:
if (tonumber(\_G.levelunlock) \>= 2) then
-- Display unlocked image etc....
end
My problem is, that its works totally randomly
. Sometimes I complete all my levels without problem and sometimes I stuck on 2nd level (only examle…it happens n other levels too…), because next level won’t open… Im totally lost, I dont understand why it happens…
Thanks for any help! [import]uid: 59968 topic_id: 14527 reply_id: 314527[/import]