Answer the question
In order to leave comments, you need to log in
How to save the values of variables to a file in JS and then load them back?
I made a simple clicker in JS. It is necessary to save the progress before exiting the game (as I understand it, the simplest thing is to save the variables to a file on the computer). When entering the game, load variables from a file into the main js code
Answer the question
In order to leave comments, you need to log in
You can save variables to a file on your computer, but it will look like downloading a file. Loading is exactly the same, through the standard file selection dialog. This can be useful for a player who wants to continue playing on another computer.
For this you will need: URL.createObjectURL , <a download>
and <input type="file">
.
Example:
If such functionality is not planned, then simply write to localStorage, or, if there is a lot of data, to indexedDB.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question