Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

What are the requirements for using cookies?

A topic by Marker Play created Jan 05, 2022 Views: 275 Replies: 2
Viewing posts 1 to 3
(3 edits)

I am a newbie. I made a game. It works OK on the local server, but doesn't save the level number here (on ITCH). If you are familiar with this problem please help. Thank you.

PS Here are two functions

function getCookie(name) {

var cookie = " " + document.cookie;

var search = " " + name + "=";

var setStr = null;

var offset = 0;

var end = 0;

if (cookie.length > 0) {

offset = cookie.indexOf(search);

if (offset != -1) {

offset += search.length;

end = cookie.indexOf(";", offset)

if (end == -1) {

end = cookie.length;

}

setStr = unescape(cookie.substring(offset, end));

}

}

return(setStr);

 }

function setCookie (name, value, expires, path, domain, secure) {

      document.cookie = name + "=" + escape(value) +

        ((expires) ? "; expires=" + expires : "") +

        ((path) ? "; path=" + path : "") +

        ((domain) ? "; domain=" + domain : "") +

        ((secure) ? "; secure" : "");

 }

// and implementation inside the game

     var expires='Sun, 2-Sep-2119 06:31:50 GMT';

     var path='';

     var domain='';

     var secure='';

     var value=0;

     level=level-0;     

     value=level+1;     

     setCookie (cook_name, value, expires, path, domain, secure);

    

Moderator moved this topic to General Development
(+4)

I'm not familiar with cookies, but I would do it with localStorage instead. It's easier, but also more appropriate for this use case.

Something like this:

localStorage.setItem('currentLevel', 1);

var level = localStorage.getItem('currentLevel');

Wow! Thank you very much. This is an answer I wanted to find! Thank you. Appreciate your help!