Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by puzzleschool

I've just about finished my game using iosImpact and I just noticed that all game data is lost if you kill the game on the iPhone and restart (obvious I know, but hadn't thought of it).

Is there a way, with iosImpact to save data more permanently so that it won't be lost between restarts or between app updates?

1 decade ago by Arantor

Push it to localStorage. localStorage should be set up the same way in iOSImpact that you would use in regular JS from what I remember.

1 decade ago by puzzleschool

Ok, thanks. I'll give that a shot.

1 decade ago by puzzleschool

Doesn't look like that works. The data didn't remain after killing the app and restarting it on the iphone.

1 decade ago by puzzleschool

Actually doesn't look like localStorage is even available in iosImpact.

1 decade ago by Arantor

It is declared in the iOSImpact headers as well as the ios plugin for Impact (it's not a normal construct in iOS, what happens is that there's some Obj-C for it in iOSImpact that defines a localStorage object, and it's called into JavaScript in the plugin, cf. the line that references native.localStorage)

1 decade ago by puzzleschool

Interesting. You're right, there is an interface to it, but it doesn't seem to retain the data if it you kill the app and restart it (it does retain data if you just go back to the home screen, but not if you stop the app from running).

Am I mistaken in this? I feel like it's hard to verify when testing, but I haven't yet been able to get any data to retain after killing the app (double tapping the home button to bring up recent apps and hitting the minus sign on the app to kill it).

1 decade ago by puzzleschool

Ok, I was mistake again :)

You have to use the localStorage.setItem('myItem', 'x') method for it to work (in html5 you can also just use localStorage.myItem = 'x' which doesn't work)

1 decade ago by puzzleschool

Thanks for the help Arantor

1 decade ago by ShawnSwander

You could store as a cookie.
called like this
username = this.getCookie("LegendsChromeUsername")
password = this.getCookie("LegendsChromePassword")

use these functions to set and get them
setCookie: function (c_name,value,exdays){
      var exdate=new Date();
      exdate.setDate(exdate.getDate() + exdays);
      var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
      document.cookie=c_name + "=" + c_value;
   },
   getCookie: function (c_name){
      var i,x,y,ARRcookies=document.cookie.split(";");
      for (i=0;i<ARRcookies.length;i++){
         x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
         y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
         x=x.replace(/^\s+|\s+$/g,"");
         if (x==c_name){
            return unescape(y);
         }
      }
   },

instead of username or password you could save game progress or a JSON object

myJSONstring= JSON.stringify(myObject)

called like this

JSON.parse(myJSONstring)

There might be limitations on cookies though as to how many per url and what size they can be depending on the user's browser and settings.

http://support.microsoft.com/kb/306070
Page 1 of 1
« first « previous next › last »