I am currently making a Flappybird game in Javacript and right now I am implementing a cookie to store the highscore. But here is the problem, the cookie is always undefined and won't change.
So that nobody is confused, I should say that I use the Framework p5.js, which helps me to draw stuff. The code is on my gitHub repository (https://github.com/HaasStefan/challengeRepo/tree/master/FlappyBird). The main code is in the file named sketch.js, but here are some snippets:
First, this is where I initialize everything, and also the cookie:
function setup() {
createCanvas(400, 600);
bird = new Bird();
menu = new Menu();
pipes.push(new Pipe());
alert(navigator.cookieEnabled);
if (typeof (document.cookie == "undefined"))
document.cookie = "highscore=0; expires=Sun, 1 Dec 2030 12:00:00 UTC; path=/";
}
Next we have the part, where the cookie is read and changed:
let str = document.cookie.split(';');
highscore = str[0].split('=')[1];
if (score > highscore) {
highscore = score;
document.cookie = "highscore=" + highscore + "; expires=Sun, 1 Dec 2030 12:00:00 UTC; path=/";
}
I really hope you can help me with this problem, because I have no idea what the bug is. Thank you!