Biggerplay Posted January 30, 2014 Share Posted January 30, 2014 What's the best way to save a games data locally? data would be level score for each of the levels. It has to work on mobile. Some kind of cookie? Looking for something like Flash's sharedObject. Quote Link to comment Share on other sites More sharing options...
Chris Posted January 30, 2014 Share Posted January 30, 2014 Have a look at localStorage! PBMCube, Biggerplay, Pooya72 and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Biggerplay Posted January 30, 2014 Author Share Posted January 30, 2014 Thanks that looks like what I need but I'm completely new to JS, how do I implement that? and specifically how do I implement that into my Phaser game? or does Phaser already have something like that built in? Quote Link to comment Share on other sites More sharing options...
alex_h Posted January 30, 2014 Share Posted January 30, 2014 I haven't used Phaser yet so I don't know whether there is any abstraction provided there, but when coding localStorage handling for my own games I found this article very helpful: http://diveintohtml5.info/storage.html There's also a smashing-magazine one that looks like it covers much of the same ground http://coding.smashingmagazine.com/2010/10/11/local-storage-and-how-to-use-it/ Biggerplay and PBMCube 2 Quote Link to comment Share on other sites More sharing options...
d13 Posted January 30, 2014 Share Posted January 30, 2014 You can use `store.js`, which is very easy to use: https://github.com/marcuswestin/store.js/ If you want more flexibility, there's LocalForage, which is cool: https://hacks.mozilla.org/2014/02/localforage-offline-storage-improved/ Biggerplay and Heppell08 2 Quote Link to comment Share on other sites More sharing options...
Chris Posted January 30, 2014 Share Posted January 30, 2014 Idk why you would need any library to use localstorage... Oo Its really just:localStorage.setItem('myItemKey', 'myContent');andlocalStorage.getItem('myItemKey');Only thing to keep in mind: localstorage can only store strings.So in order to store whole objects, do this:localStorage.setItem('myObject', JSON.stringify(myObject));and in reverse:myObject = JSON.parse(localStorage.getItem('myObject')); Finders_Keepers, valueerror, issey and 4 others 7 Quote Link to comment Share on other sites More sharing options...
Biggerplay Posted January 30, 2014 Author Share Posted January 30, 2014 @Chris store.js looks pretty good though? Quote Link to comment Share on other sites More sharing options...
1-800-STAR-WARS Posted January 30, 2014 Share Posted January 30, 2014 Idk why you would need any library to use localstorage... Oo Its really just:localStorage.setItem('myItemKey', 'myContent');andlocalStorage.getItem('myItemKey');Only thing to keep in mind: localstorage can only store strings.So in order to store whole objects, do this:localStorage.setItem('myObject', JSON.stringify(myObject));and in reverse:myObject = JSON.parse(localStorage.getItem('myObject')); Mainly backwards compatibility - something like Amplify allows you to store using a single API which gracefully degrades from localStorage to sessionStorage, globalStorage, userData and finally an in-memory store if none of the above is available. This ensures compatibility with browsers as far back as IE5... Not that your game would otherwise work in that browser Finders_Keepers and TNelson 2 Quote Link to comment Share on other sites More sharing options...
Chris Posted January 30, 2014 Share Posted January 30, 2014 Afaik, all browsers that support <canvas> also support localStorage. So... well, enough sayed 1-800-STAR-WARS and Finders_Keepers 2 Quote Link to comment Share on other sites More sharing options...
robertbrooks Posted February 1, 2014 Share Posted February 1, 2014 On a side note , if you do use local storage to store level data and user data, your game will be easily hackable by any user from the browser console (unless you do some crazy encrypt code and checking) . I always use local storage becuase I don't care if my users hack the game to get to more advanced levels but this might be something you might not want to happen. Yeah and there's no need to use a library to use local storage for game. plus if you're new to javascript and html5 then i would recommend learning how js works before using a library. especially for something as simple as local storage. Pooya72 and PBMCube 2 Quote Link to comment Share on other sites More sharing options...
Vaughan Posted May 13, 2014 Share Posted May 13, 2014 Your game can be hacked either way, JS is running client-side. liakos1992 1 Quote Link to comment Share on other sites More sharing options...
PAEz Posted May 24, 2014 Share Posted May 24, 2014 @Vaughan Sometimes its just a case of not making it too easy. Once it becomes general knowledge that games store things in local storage and all the kid needs to do is go to the web inspector and have a look, it all gets too easy. So even if its really weak as hell at least its going to take looking in the code to cheat and not just local storage.For instance, which one of these is easier to cheat with?.....{lives:3}....or...ÅÌAnd thats using one of the oldest, weakest methods there is ......function dyslexia(string){return String.fromCharCode.apply(this,string.split('').map(function(a){return a.charCodeAt()^255;}))}var a = "{lives:3}";var z = dyslexia(a);a == dyslexia(z); PS. I dont think that function would work right with unicode stuff (couldnt be bothered checking), if thats the case just btoa it first and in your ascii land. Quote Link to comment Share on other sites More sharing options...
Wavertron Posted May 29, 2014 Share Posted May 29, 2014 For me, if its a single player game that runs entirely locally, no backend, and doesn't share scores socially or integrate externally, I wouldn't even bother with any attempt to protect the local storage data. If they want to cheat fine, at least they are still playing your game! Quote Link to comment Share on other sites More sharing options...
PAEz Posted May 29, 2014 Share Posted May 29, 2014 @Rudy But for much less time than they would if they didnt cheat. Plus from a couple of people I know....If they can cheat their appreciation of the game will drop. I thnk this because of my bro in law. He use to cheat on EVERYTHING! I use to spend alot of time making cheats for him on the original xbox. Then 360 came out and he couldnt cheat anymore....Hes the one that told me that since not being able to cheat he actually enjoyed playing games more. Why? Who knows exactly. But personally I think its because hes pushed through the frustration of loosing and learnt that joy full feeling of being a true winner. Its the pain followed by the completion that truly makes you feel. Quote Link to comment Share on other sites More sharing options...
Mysticcoder12345 Posted September 1, 2020 Share Posted September 1, 2020 On 1/30/2014 at 7:46 AM, Chris said: i did it but i dont think it works? pls help Idk why you would need any library to use localstorage... Oo Its really just: localStorage.setItem('myItemKey', 'myContent'); and localStorage.getItem('myItemKey'); Only thing to keep in mind: localstorage can only store strings. So in order to store whole objects, do this: localStorage.setItem('myObject', JSON.stringify(myObject)); and in reverse: myObject = JSON.parse(localStorage.getItem('myObject')); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.