0
\$\begingroup\$

I'm coding (or at least trying to code) a single player game in pure JS. I was wondering how I was gonna be able to write data without having the user setting up a server or a database, only way I found is local storage.

I'm aware that this kind of data is attached to the browser but I don't think someone would swap between browser, IMHO people start with one and stick to it. What I'm more concerned about is what else in the local system can modify this storage?

For instance, can cleaning up applications remove the JSON I put in there?

\$\endgroup\$
1
\$\begingroup\$

Local Storage is very similar to how cookies work. It's basically saving some data locally. These data are only accessible to the same browser on the same machine only.

It may be possible for some browsers to share the same cookies, or export/import, but that's in general the exception.

The user clearing all browser data will wipe out your game's save, which is normal, and users are expecting this for the most part.

If you want users to share their saves across browsers/devices/platforms, then you need some way to save that online. There are some libraries that already do that for you, or websites that if you host your game there are willing to let you use cloud saving.

If it's your first game, or you are still learning, I would say to not bother with cloud saving. Making a game is already a difficult task as it is, and supporting cloud saves just adds to the complexity. At the minimum you can have a button to export all saves to a single file, and an import button to import such files, that way if a user wants to keep their save, there is a way to do it.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I have experience in game dev and I wanted to see if I could make a game running locally, I'm just scared that another app could be able to remove the data I put in the local storage between sessions, like PC-cleaners for instance? \$\endgroup\$ – Axel Carré May 6 at 18:33
  • \$\begingroup\$ @AxelCarré Other programs will not specifically target your game's local data. If a program decides to delete all browser's saved data, then the user will lose everything, and there's not much you can do against that. It's worth noting that you can't save data to files, as that's a massive security concern, so browsers don't allow that. As far as I'm aware, these type of data is for the most part only deleted by the user themselves, which you can't (and shouldn't) stop. \$\endgroup\$ – TomTsagk May 6 at 23:52
  • \$\begingroup\$ @AxelCarré Of course assuming you implement local storage, if you decide to do save on the cloud, that comes with its owns pros and cons. \$\endgroup\$ – TomTsagk May 6 at 23:52
  • \$\begingroup\$ Thanks for your answer, I'm sorry and glad at the same time that I have to tell you that your answer made me think that pure JS is going to be too much effort for something I could make in C++ for instance. Thanks again you saved me from weeks of work! \$\endgroup\$ – Axel Carré May 7 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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