GOT IT! The pieces of code below work both on the simulator and the iphone.
Here it is and maybe someone will benefit from it. I tried to comment it so to make it easier:
[lua]------ in main.lua-------------
require( “ice” )
settings = ice:loadBox ( “settings” )
settings:storeIfNew(“version”, 1.0)
settings:storeIfNew(“musicOn”, true)
settings:storeIfNew(“fxOn”, true)
settings:storeIfNew(“gameMode”, 1)
settings:storeIfNew(“gameLevel”, 3)
settings:storeIfNew(“isGameSaved”, false )
settings:storeIfNew(“gameCounter”, 30000)
settings:store(“gameTimer”, {10000,20000,30000})
player1 = ice:loadBox ( “player1” )
player1:storeIfNew(“name”, “player1”)
player1:storeIfNew(“score”, 0)
player1:storeIfNew(“hiScore”,0 )
player1:storeIfNew(“medals”, {0,0,0} )
player1:storeIfNew(“promotion”,0)
player1:storeIfNew(“rank”, 1)
player1:storeIfNew(“bonus”,0)
player1:storeIfNew(“bullet”,1000)
---- in module X (on top of module X)…here module X is my main game screen (but I used the ----- same thing in options screen for instance)
local hiScore
local musicOn
local fxOn
local gameLevel
local gameMode
local gameCounter = { }
— then in the initVars section (at the bottom of the module X if using director…) I retrieve all the ----- variables from memory (remenber that load from disk in main.lua)
hiScore = player1:retrieve( “hiScore”)
hiScoreText.text =string.format ( “%08d”, hiScore )
musicOn = settings:retrieve( “musicOn”)
fxOn = settings:retrieve( “fxOn”)
gameLevel = settings:retrieve( “gameLevel”)
gameMode = settings:retrieve( “gameMode”)
gameCounter = settings:retrieve( “gameCounter”)
– reload the gameTimer that depends on the game level the user selected in the Options Screen ---- (another module)
local temp = settings:retrieve( “gameTimer”)
gameTimer[gameLevel] = temp[gameLevel]
print("game timing = "…gameTimer[gameLevel])
----------- Every time something change while in module X like a new high score then I do this to ----save the new high score (for instance) to memory.
player1:store(“hiScore”,highScore )
– Finally when I am about to exit module X (and go back to my main menu module) then I simply save to disk like this:
player1:save()
settings:save()
---------------------------------THAT’S IT !!!-------------------------------------[/lua]
The only thing I do not like is that fact is that the ice boxes settings and player1 are global variables (not sure if that really cause less performance but when you play with lua, everybody “hate” globals and so now I “hate” globals too:)
In any event I want to specially thank you Naomi for sticking with me all these last few days. I REALLY appreciated it. Of course thanks to Graham for coming up with ICE in the first place (AND for storeIfNew!) for When you understand it, it really child play to add a powerful load/save feature to your game.
In any event, I will see if I can remove the use of globals in the code above since ice box contains the data to accessed between modules as well as between app re-start. OR maybe i will just leave it alone if it does not interfer with the game performance/memory size…
THANKS to all.
Mo
ps: You noticed I used player1 as an ice box. The reason is that i am hoping to add local multiplayer mode so I will think I will just need to add a player2 ice box to the mix…
[import]uid: 49236 topic_id: 16634 reply_id: 67332[/import]