ICE module, initial loadup.

Hi there,
I’m using the ICE module.

My question is to others who have used it about the first ever app loadup.

Currently i load my ‘icebox’ and then retrieve some data from it.
If it doesn’t exist i create it as the default value.

myData = ice:loadBox( "myData" )  
  
local MuteSound = myData:retrieve( "MuteSFX" )   
local MuteMusic = myData:retrieve( "MuteMusic" )  
local Coins = myData:retrieve( "Coins" );  
  
if (MuteSound == nil) then  
 myData:store("MuteSFX", 0);  
 myData:save("MuteSFX");  
 print("SFX Saved")  
end  
  
if (MuteMusic == nil) then  
 myData:store("MuteMusic", 0);  
 myData:save("MuteMusic");  
 print("Music Saved")  
end  
  
if (Coins == nil) then  
 myData:store("Coins", 0);  
 myData:save("Coins");  
 print("Coins Saved")  
end   
...  

The very first time an app is played, it’ll go through creating all the data. Any subsequent time it wont.

Is this the best way to do this?
Since i have alot and maybe more! But i can’t think of a way to save them all or state them all without doing it this way.

How do you people do it?

Thanks,
Matt [import]uid: 91798 topic_id: 21932 reply_id: 321932[/import]

You can store data in tables using ice, this will help you avoid all those calls to load and save different values.

Try something along these lines:

myData = ice:loadBox( "myData" )  
  
local settings = myData:retrieve( "settings" )  
if (settings == nil) then  
 settings["MuteSFX"] = 0;  
 settings["MuteMusic"] = 0;  
 settings["Coins"] = 0;  
 myData:store("settings", settings);  
 myData:save();  
end  

Isn’t Ice great? :slight_smile: [import]uid: 87138 topic_id: 21932 reply_id: 87225[/import]

Hi,

there is storeIfNew function in ice

you probably can call something like this in main.lua

[lua]gameSettings = nil
local gameSettings = ice:loadBox( “gameSettings” )

gameSettings:storeIfNew( “MuteSFX”, 0 )
gameSettings:storeIfNew( “MuteMusic”, 0 )
gameSettings:storeIfNew( “Coins”, 0 )

gameSettings:save()[/lua]

@Revaerie Ice is Awesome! [import]uid: 74883 topic_id: 21932 reply_id: 87226[/import]