Saving with Ice

I’m using Ice to save my game data when I close my app.
It works on the last stable build, and not on later daily builds. (I need later builds to overcome the new-iPad display issue that got fixed).
BUT–even when it works (i.e. saves the stats upon closing out of the app) then I have this problem:

If I leave the app without closing, then come back into the app, it restarts, which is very undesirable if you are mid-level in my game. This is my save code for when my app closes…

[lua]function onSystemEvent( event )
if( event.type == “applicationExit” ) then

savedata:storeIfNew(“levelsbeaten”, _G.levelsbeaten)
savedata:store(“levelsbeaten”, _G.levelsbeaten)
savedata:save()

end
end[/lua]

I need my app to both save upon actual closing the app, AND not restart when the app is just running in the background. I don’t know if it is an issue with Ice, the corona builds, or my code.

Thanks,
Dane [import]uid: 117490 topic_id: 27378 reply_id: 327378[/import]

Small update: I made a build of my game using the last stable release, and without the save code. Leaving the app (but not closing it) in mid-level still causes the app to “reboot” when I come back into the app, so that issue is unrelated to my save issue.

Essentially I cannot get Ice to save in later daily builds, such as build 821, although it works in the simulator (just not my iPhone or iPad).

Thanks,
Dane [import]uid: 117490 topic_id: 27378 reply_id: 111253[/import]

Hey, Dane@dogfish apps, I am able to save data using ICE with the latest daily build 828 (iOS universal build.) Anyhow, I think the problem you are having is probably unrelated to daily build.

By the way, since you’re using store function, you don’t need storeIfNew.

Naomi [import]uid: 67217 topic_id: 27378 reply_id: 111279[/import]

Thanks for your reply, Naomi.

I have now gotten it to save to Ice if I put the ‘require’, ice:loadBox, and store/save all in my home screen. So there’s got to be something that the onSystemEvent/ApplicationExit code doesn’t like. I’ve messing around with making variables into globals, and placing stuff inside of the onSystemEvent function, but still no luck. [import]uid: 117490 topic_id: 27378 reply_id: 111284[/import]

Naomi do you think I could send you my code, I am going insane trying to get this to work. I’m usually pretty good about figuring things out but (ignoring the save-on-exit functionality for now) I can get my game to save with my save code in my “info” scene, but if I cut and paste it to my “home screen” scene, it doesn’t work. I use module…packageseeall, and a function new()…end for each scene. They are identical as far as I can tell. This is practically the last thing I have to do before submitting my game and I am just getting nowhere with it.

Thanks :frowning:
Dane [import]uid: 117490 topic_id: 27378 reply_id: 111385[/import]

Welp, my save-on-ApplicationExit code works in the last stable build (704) but doesn’t work on build 821 (the most recent one that doesn’t introduce an unrelated bug).

Guess I need to find out what in the newer builds is causing me to not be able to save on exit… [import]uid: 117490 topic_id: 27378 reply_id: 111399[/import]

Make sure you are using the latest version of ICE: https://github.com/GrahamRanson/Ice

Or contact the author of ICE (Graham Ranson) http://www.glitchgames.co.uk/ [import]uid: 84637 topic_id: 27378 reply_id: 112154[/import]

I had the same issue, in the previous public release ICE was working fine but with the latest public release (2012.840) the json.encode returns empty values, thus nothing being saved.

Fixed it by using a pure lua json module and replacing the json.decode and json.encode.

Don’t know if this related to ICE or the Corona core json functions. I cannot imagine the json function are not working…? [import]uid: 110108 topic_id: 27378 reply_id: 112778[/import]

I had the same problem, in new release ICE is not working. ICE always return a nil value. After using the new version of ICE there is problem with encode and decode as @oguz.karadeniz said ICE is working fine previous public release i’m agree with him… Please fix this issue with ICE in new public release [import]uid: 132856 topic_id: 27378 reply_id: 112996[/import]

I’d the same problem when i try to build my app with pro developer account, ice is working fine on 704a but when i try to build with 760 or later it doesn’t work, and show an error on ice:loadBox error was in ice.lua … bala bala :-p (a nil value) and i’m stack with this problem :frowning: when i comment out the loadBox then work fine… :expressionless: [import]uid: 153141 topic_id: 27378 reply_id: 112139[/import]

@Danny after using the new version of the ICE, now i’m face the problem in encoding and decoding. When i saved the data, it’ll remain saved until i’m in the app as i closed the app with saved data and when again i run the app all saved data gone… [import]uid: 153141 topic_id: 27378 reply_id: 112997[/import]

@All: We can’t fix issues with ICE as we didn’t create it and we can’t support third party libraries. If you guys are having issues with it, you will need to contact the author of ice “Graham Ranson”.

[import]uid: 84637 topic_id: 27378 reply_id: 113206[/import]

@Danny then what you suggest for data saving??? [import]uid: 153141 topic_id: 27378 reply_id: 113381[/import]

I would suggest using json.

http://blog.anscamobile.com/2011/08/tutorial-exploring-json-usage-in-corona/ [import]uid: 84637 topic_id: 27378 reply_id: 113657[/import]