Question:how do i make a save load system for my clicker game
Repl link:
code snippet
Question:how do i make a save load system for my clicker game
Repl link:
code snippet
Is this on a website?
on repl its called coconutclicker
For just a static website, I would look into using localstorage to save scores. Be aware however, that users will have full control of what you store in localstorage, so they could fake their scores.
If you need the scores to be trustworthy, you’ll need to write a backend and connect that to a database.
ok but can you try to help me? with the coding
This would have to be moved to collaboration then. @not-ethan could you do this? or @hugoondev or @MattDESTROYER
You can use localStorage
as CodingCatus recommended.
window.localStorage.setItem("name", "value");
window.localStorage.getItem("name", null); // the second parameter is what will be
// returned if nothing is stored with the name 'name'
Note that localStorage
cannot store objects, so you will need to stringify them first:
window.localStorage.setItem("name", JSON.stringify({ property: "value" }));
And you can parse them similarly into an object:
JSON.parse(window.localStorage.getItem("name", "{}"));
localStorage
saves data locally at the host of the site (so sub paths should still be able to access this info).
If you want to be able to see/use this data in a way that is visible to anyone other than the user themself, you will need a server. If you need help setting one up I’m happy to give you guidance (or if you make a bounty I’m happy to just set everything up for you)
I could do this as a bounty too!
how do i use local storage?
localStorage
is a key-value based system for storing strings on a user’s device (via the browser).
Using localStorage
is easy, you can get it set items on the storage using the getItem
and setItem
functions.
localStorage.setItem("my locally stored variable", "Hello world!");
console.log(localStorage.getItem("my locally stored variable")); // -> "Hello world!"