I’m trying to make a game that has a map editor, and I would like to save layers locally to the file system. Can somebody help me to add this feature? And I also don’t have anything because I don’t know where to start, so I don’t have any code to show.
Asked
Active
Viewed 103 times
1 Answers
1
In JavaScript/HTML5 you cannot save to a file without a user action. You can present the user with a save-file dialog and then save whatever data you have to a file, see this question.
Alternatively, you can just save your layers objects to the local storage, which is storage within the browser cache. The only downside is that if you open the same page in a different browser (for example switch from FireFox to Chrome) then the save is not available. For more information, see this question.

BdR
- 2,770
- 2
- 17
- 36
-
Sorry, I can't provide custom code for your objects and your project, you'll have to create it yourself. But I will say that Javascript objects can easily be converted to plain-text strings using Javascript's built in `JSON.stringify(myobj)` function, you can save the text to file or localstorage. And then later you can read from a text and use `JSON.parse(mystr)` to convert it from string back to an object again. – BdR Jul 04 '19 at 08:46