Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

OK, let's say I have a JavaScript game (preferably on jQuery framework) and its using HTML5 Canvas.

What would be your way of storing data to map out shops, monsters, and NPCs? I was thinking maybe JSON txt files on the website? Or maybe simple text files and simple delimiters? I am not sure. How would you store that kind of data?

share|improve this question

closed as not constructive by Byte56, Trevor Powell, Laurent Couvidou, Josh Petrie, sam hocevar Jan 29 '13 at 22:24

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Basically, if you want to prevent people from directly accessing data on the server, ajax + post + database can accomplish that. However, if you want to prevent your data from being transparent once its loaded into js, you'll need to get creative - and that's a topic for chat. – CodeMoose Jan 28 '13 at 17:06
up vote 4 down vote accepted

JSON is definitely the way to go, it's nice and lightweight. Though, storing the data in a database is probably more secure than static files on the server - it prevents people from accessing the files directly. JQuery makes it insanely easy to execute ajax queries, you'll just need a simple PHP (or maybe ASP, depending on your host) script for the ajax to call, to handshake info between javascript and the database. Some quick hunting on google reveals a ton of tutorials and demo classes, so even if you don't have any server-side scripting knowledge, it shouldn't be an obstacle. Best of luck!

share|improve this answer
-1 for the "security" argument. Storing in a database doesn't have anything to do with the fact that people can access it or not. If the data arrives on the client, the user can just intercept it anyways. Or send the request himself, which will be handled from a database. Or read the data from the client-side Javascript. – Liosan Jan 27 '13 at 10:05
Yes, well, the information in the database is hidden away while if people can see where the request from something like "monsters.json" ... they can see every monster mapped out. So... how could I fix that? – naknode Jan 27 '13 at 13:50
Why do you want to fix that? Besides, the database is not really hidden away. Not any more that your files. After all, if the user can see the url server/monsters.json, they can also see the AJAX url server/index.php?req=getMonsters – Liosan Jan 27 '13 at 16:12
@Liosan Only if you send ajax as a GET. Jquery boils POST requests down to the easiest possible form (pretty much give it an associative array of key-value pairs), which thwarts direct access attempts on the php script as long as you only process POST variables. You can also restrict the response to certain http_referrers, preventing people from accessing via their own scripts. Will it stop a soviet supercomputer? No. Will it stop your average basement hacker? Most likely. – CodeMoose Jan 28 '13 at 2:21
@Liosan That's a good point - no matter how you protect things on the server side, once javascript has the data it's transparent. Maybe there's some way to be more minimalist in the data handling? Sounds like it's time to send this over to chat. – CodeMoose Jan 28 '13 at 16:57

JSON would be fine, so would anything else. You can use XMLHttpRequest to load it, or some other technique as you see fit.

JQuery really doesn't buy you anything, it's almost exclusively for manipulating the DOM, if you use Canvas, you don't need it (You still need a DOM, but it probably very rarely changes).

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.