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

9 years ago by Dave

Curious as to how one can save game data? For either high scores or for user's to come back later and carry on at X level?

9 years ago by dominic

Currently there's no built-in way to do that. Depending on how much data you want to save, you could just use cookies, or if you need more, HTML5 local storage.

Providing Save Game facilities is definitely on the roadmap for this major version, though.

9 years ago by Dave

Guess you could also use this in conjunction with couchDB. Liking this a lot though :)

9 years ago by htilford

lawnchair comes to mind

9 years ago by dariusk

For a really simple cookie-based solution, check out the dataSave and dataLoad functions in Akihabara:

(Begins line 753)
https://github.com/kesiev/akihabara/blob/master/akihabara/gbox.js

To save you just manipulate document.cookie directly. A simplified version (NOT TESTED) would be:

function save () {
document.cookie = document.cookie + "~" + key + "=" + value + "; expires=" + date.toGMTString() + "; path=/";
};

Then your load function would accept a key as a parameter, and run some kind of regex/substr combo on the document.cookie string to find your value.

9 years ago by dariusk

My mistake, I forgot to set the value for date, which basically says "this cookie expires in 100 years":

function save () {
date.setTime(date.getTime()+((d?d:365*10)*24*60*60*1000));
document.cookie = document.cookie + "~" + key + "=" + value + "; expires=" + date.toGMTString() + "; path=/";
};

9 years ago by techmale

if you want a simple save/load method, combine cookies with JSON2.
Push all your data into a JSON object, then use stringify to convert it to string form.

The advantage to this is that parsing the reloaded data is just one function call (parse(string)), and you have your data object back.

9 years ago by BFresh

I've had luck using the HTML5 local storage feature with the .getitem and .setitem methods. Not to say its the best but it is very simple. The browser takes care of the data and it persists (must be same PC, same browser). The next thing I'd like to do is look into online saving associated with user accounts, but this works well for me for local storage and best of all, no extra API's or anything since it's built into HTML5 now!

//Check for saved level
this.savedlevel = localStorage.getItem('Level');

//Save current level
localStorage.setItem('Level', currentlevel);

9 years ago by fugufish

you could also do POST and GET methods to your databases.

9 years ago by Ken

I agree with fugufish. You can just use ajax to record the players scores, states, etc... server side, that way you don't have to worry about clients side storage and the player can access their data from wherever they want to play, home/work/etc... Plus you will be able to do things like leader boards and other competitive features that will cause people to come back and play again. I'm a big fan of jQuery for ajax.

But, now it's time for some shameless self promotion. :) If you don't want to write all the backend code, checkout TapJS.com . It takes care of all the things you mentioned like scores, games state, etc.. with just a couple lines of js.

8 years ago by niteflyx

@Ken
How does TapJS's security work for things like scores, game states, etc., if all that client is rendered on the client side?

8 years ago by Ken

Hey niteflyx! I take it by security your are referring to securing your game code from things like cheating, correct? Well as you mentioned that with html5/js you are handing your games source code over to the client, you are pretty limited in your options at this point in time. We had a pretty nice discussion about that here http://impactjs.com/forums/everything-else/secure-code

Essentially the only way to "secure" your game would be to run the logic server side and use your client side js purely to render what the server tells it. So I am in the early stages of planning that for TapJS. I'm exploring a couple options, including an option using node.js

If you are asking because you want to monetize your game, there are plenty of ways to do so in html5 check out http://impactjs.com/forums/everything-else/so-sad-an-observation-of-monetization-tactics for some different ideas.

I hope that answers your question. If not, let me know.

Best of luck

8 years ago by jsantell

@Ken
Hey, I made the previous post from my first account, thanks for the reply, Ken! I've spent substantial time trying to figure out how to have legitimate data from the client to use (leaderboards, for example), more so for game purposes rather than obfuscation to "secure" it.

Thanks for the links!

8 years ago by Ken

@jsantell - Very cool. I would love to hear what you came up with. One possible method you probably thought of is a token based system where the server issues a request token for the game/player combo that is valid for X time. Again this does not get around hacking as anyone can see your "security logic".

8 years ago by jsantell

@Ken
Yeah, thought of the token system.. they'd have the token, they could do whatever they wanted with it at that point; I think I've given up on it for the time-being, heh.

8 years ago by Ken

Yep exactly, they have the full source code, you're options are pretty limited :) Giving up on the worry is the same conclusion that we all came to in that thread. :) Honestly I think the worry about cheating is highly over hyped. Unless the result of someone cheating is a monetary loss to another player, then the damage is pretty low. Plus you can always just put some logic on the back end to watch for too many high scores, too high of scores or radical changes in a players scores, etc...

Eh, not even worth it. :) I would love to check out your games, if you have any public then post the links :)
Page 1 of 1
« first « previous next › last »