Ask coding questions

← Back to all posts
Cookies
JacobMcPherson1

How do i save game progress with cookies?

Voters
JacobMcPherson1
Comments
hotnewtop
Coder100

I would more recommend localStorage, so much easier to use, and you don't have to worry about expiration.

just like that! That's it! The value has to be a string, however.

and then to get a kei:

Number() just converts it into a number, which is useful for us.

JacobMcPherson1

@Coder100 so I just put both those lines in and it'll save your cookie amount?

Identity-Unknown
JacobMcPherson1

@Identity-Unknown bro wtf

SameeraMurthy

Solution

In JavaScript, you can create cookies with document.cookie.

But if you want to use more features out of
cookies, check out
https://www.w3schools.com/js/js_cookies.asp

It also gives you some code to create a wrapper function for setting and getting cookies.
https://www.w3schools.com/js/tryit.asp?filename=tryjs_cookie_username

You can also save info with localStorage.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
https://www.w3schools.com/html/html5_webstorage.asp