How to implement "ice"?

I’ve been working on an ingame shop, and since Corona lacks an inherent method to saving data, I’m using ice: http://developer.coronalabs.com/code/ice

But I’m not quite sure on how to implement it. I’d like to use it for the inventory and credits, but I’m currently stuck on credits.

I tried this:

credits = ice:loadBox( “credits” )
credits:storeIfNew( “credits”, 200 )
creditsText = display.newText(credits, 400, 0, native.systemFont, 36)

But that just gave me an error of some bad argument stack traceback… Anybody have any experience with ice? [import]uid: 200198 topic_id: 34698 reply_id: 334698[/import]

Have you tried using GGData by glitch games?

The guy who made Ice is part of Glitch games now, so GGData is kinda a more upto date version of Ice and well documented.

Link here: https://github.com/GlitchGames/GGData [import]uid: 62706 topic_id: 34698 reply_id: 137885[/import]

Try the preference library I wrote…
Should be pretty easy to work with! [import]uid: 64174 topic_id: 34698 reply_id: 137946[/import]

Like Deano says, go get GGData. It’s works similar to ICE, but without the issues some have reported or take a look at Preference ( I haven’t worked with it yet).

I’ve got several apps that use ICE with no problems, but have moved to GGData. Converting from ICE to GGData is quite easy to implement.

That said, ICE is not your problem here though, I don’t believe.

You are not calling the value correctly.

Try this, I’ve surrounded the value with some text to show how that can be done also, I think it should resolve your issue.

require("ice")  
  
credits = ice:loadBox( "credits" ) --I usually leave my iceBox "Global" so it can be easily called from other modules, not sure if it is the way to go, but works for me  
  
credits:storeIfNew( "credits", 200 )  
credits:save()  
  
local creditsText = display.newText(credits:retrieve("credits", value) , 100, 100, native.systemFont, 36)  
  
local creditsText2 = display.newText("I've got " ..credits:retrieve("credits", value).. " Credits" , 100, 200, native.systemFont, 36)  

Hope this helps,

Nail [import]uid: 106779 topic_id: 34698 reply_id: 137951[/import]

You need some water, some kind of container, and a freezer.
Sorry couldn’t resist [import]uid: 7911 topic_id: 34698 reply_id: 137974[/import]

Okay, I’m currently looking at this GGData, and it looks simple enough to switch over to… Can I use this with Storyboard?

I’m going to use ice/GGData to manage the inventory of what a player can buy in a shop, but it should of course be a global table.

I’m sure I’ll find this out soon enough, as I’m currently doing a few tests with the storyboard, but maybe some of you have some insightful tips or tricks? [import]uid: 200198 topic_id: 34698 reply_id: 138098[/import]

Okay, I’m looking at Preference now… and its super simple to use!

I do have a question though, how would I go about changing the value of a table field?

To take your example:

preference.save{d = {1,"2",true}} value = preference.getValue("d")

How would I go about changing just the true, to false?
Would I have to do it this way:

preference.save{d = {1,"2",false}}

I’m hoping for an easier solution (and a more elegant one)

I tried

preference.save{d[3] = false}

But that sadly didn’t work [import]uid: 200198 topic_id: 34698 reply_id: 138116[/import]

@tomas

You can just roll out your own function for syntactic sugar…
Say something like
[lua]
local function modifyTable(key,value)
local s,e = key:find("%[.*%]")
local table = key:sub(1,s-1)
local tableIndex = key:sub(s+1,e-1)
–basically we have variable table contains ‘d’ and variable tableIndex contains ‘3’

local stored_value = preference.getValue(table)
stored_value[tableIndex] = value
preference.save{[table] = stored_value}

end

modifyTable(“d[3]”,1)[/lua]
so if you have a file d, d[3] will be set as 1 and stored… [import]uid: 64174 topic_id: 34698 reply_id: 138131[/import]

I’ve actually done it in a slightly easier way (at least, I find it easier)

I just create a table normally, then save that table using Preference. And in doing so, I can just keep manipulating the table as I normally would, while still saving it (and of course loading it).

A little easier to do for someone who’s just starting out :smiley: [import]uid: 200198 topic_id: 34698 reply_id: 138142[/import]

lol! he he! that does sound simple!
Sometimes I think too much :frowning: [import]uid: 64174 topic_id: 34698 reply_id: 138144[/import]

Have you tried using GGData by glitch games?

The guy who made Ice is part of Glitch games now, so GGData is kinda a more upto date version of Ice and well documented.

Link here: https://github.com/GlitchGames/GGData [import]uid: 62706 topic_id: 34698 reply_id: 137885[/import]

Try the preference library I wrote…
Should be pretty easy to work with! [import]uid: 64174 topic_id: 34698 reply_id: 137946[/import]

Like Deano says, go get GGData. It’s works similar to ICE, but without the issues some have reported or take a look at Preference ( I haven’t worked with it yet).

I’ve got several apps that use ICE with no problems, but have moved to GGData. Converting from ICE to GGData is quite easy to implement.

That said, ICE is not your problem here though, I don’t believe.

You are not calling the value correctly.

Try this, I’ve surrounded the value with some text to show how that can be done also, I think it should resolve your issue.

require("ice")  
  
credits = ice:loadBox( "credits" ) --I usually leave my iceBox "Global" so it can be easily called from other modules, not sure if it is the way to go, but works for me  
  
credits:storeIfNew( "credits", 200 )  
credits:save()  
  
local creditsText = display.newText(credits:retrieve("credits", value) , 100, 100, native.systemFont, 36)  
  
local creditsText2 = display.newText("I've got " ..credits:retrieve("credits", value).. " Credits" , 100, 200, native.systemFont, 36)  

Hope this helps,

Nail [import]uid: 106779 topic_id: 34698 reply_id: 137951[/import]

You need some water, some kind of container, and a freezer.
Sorry couldn’t resist [import]uid: 7911 topic_id: 34698 reply_id: 137974[/import]

Okay, I’m currently looking at this GGData, and it looks simple enough to switch over to… Can I use this with Storyboard?

I’m going to use ice/GGData to manage the inventory of what a player can buy in a shop, but it should of course be a global table.

I’m sure I’ll find this out soon enough, as I’m currently doing a few tests with the storyboard, but maybe some of you have some insightful tips or tricks? [import]uid: 200198 topic_id: 34698 reply_id: 138098[/import]

Okay, I’m looking at Preference now… and its super simple to use!

I do have a question though, how would I go about changing the value of a table field?

To take your example:

preference.save{d = {1,"2",true}} value = preference.getValue("d")

How would I go about changing just the true, to false?
Would I have to do it this way:

preference.save{d = {1,"2",false}}

I’m hoping for an easier solution (and a more elegant one)

I tried

preference.save{d[3] = false}

But that sadly didn’t work [import]uid: 200198 topic_id: 34698 reply_id: 138116[/import]

@tomas

You can just roll out your own function for syntactic sugar…
Say something like
[lua]
local function modifyTable(key,value)
local s,e = key:find("%[.*%]")
local table = key:sub(1,s-1)
local tableIndex = key:sub(s+1,e-1)
–basically we have variable table contains ‘d’ and variable tableIndex contains ‘3’

local stored_value = preference.getValue(table)
stored_value[tableIndex] = value
preference.save{[table] = stored_value}

end

modifyTable(“d[3]”,1)[/lua]
so if you have a file d, d[3] will be set as 1 and stored… [import]uid: 64174 topic_id: 34698 reply_id: 138131[/import]

I’ve actually done it in a slightly easier way (at least, I find it easier)

I just create a table normally, then save that table using Preference. And in doing so, I can just keep manipulating the table as I normally would, while still saving it (and of course loading it).

A little easier to do for someone who’s just starting out :smiley: [import]uid: 200198 topic_id: 34698 reply_id: 138142[/import]

lol! he he! that does sound simple!
Sometimes I think too much :frowning: [import]uid: 64174 topic_id: 34698 reply_id: 138144[/import]