help with js cookies

Status
This thread has been locked.

X8.

Developer
Premium
Feedback score
14
Posts
1,040
Reactions
612
Resources
0
So.. I'm trying to make this mineman clicker game (Like cookie clicker), and I need to know how to read, create, and delete cookies for when the user goes to the website, so their data saves.

code:

var diamondCount = 0



function diamondClick(){
diamondCount += 1;

var diamonds = document.getElementById("diamonds");

diamonds.innerHTML = diamondCount;
}
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Shaun

Web Developer, owner of Syncore LLC
Supreme
Feedback score
20
Posts
622
Reactions
408
Resources
0
I don't want to use a lib or a api for this, I want to use something like this: https://www.w3schools.com/js/js_cookies.asp, but im not sure where to start.
Eh the way to do cookies in vanilla JS is really annoying/not well implemented.

Essentially you will need to create a function that will store a cookie using "document.cookie = ...". You will need to store your data in a string of variables, ex: "var1 = 'Hello World', var2= 1". You can then get cookies by setting a variable to equal "document.cookie" such as the following: var x = document.cookies. From there you can parse the string into an array and then change values but I don't recommend this at all, it's easier to use the library I posted above if you want to utilize cookies.
 

X8.

Developer
Premium
Feedback score
14
Posts
1,040
Reactions
612
Resources
0
Eh the way to do cookies in vanilla JS is really annoying/not well implemented.

Essentially you will need to create a function that will store a cookie using "document.cookie = ...". You will need to store your data in a string of variables, ex: "var1 = 'Hello World', var2= 1". You can then get cookies by setting a variable to equal "document.cookie" such as the following: var x = document.cookies. From there you can parse the string into an array and then change values but I don't recommend this at all, it's easier to use the library I posted above if you want to utilize cookies.
Alright thanks.
 
Status
This thread has been locked.
Top