M
M
Mikhail Golubev2019-07-23 10:42:59
JavaScript
Mikhail Golubev, 2019-07-23 10:42:59

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

2 answer(s)
K
Konstantin Kitmanov, 2019-07-23
@Mr_Liqid

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.

A
Alexander, 2019-07-23
@lebonnet

localStorage
sessionStorage
IndexedDB

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question