HTML & JS - How to make an incremental/clicker game - #3 Saving/Loading - androidgamestore.net

HTML & JS – How to make an incremental/clicker game – #3 Saving/Loading

Tanktot Games
Views: 1402
Like: 37
In this tutorial I show you how to add saving and loading functionality into your incremental game.

I dive into the fundamentals of saving variables into the localstorage of a browser through JS. I also dive into the basics of objects and how to access their variables. This tutorial uses solely JS with a few lines of HTML.

Watch Part 2:

Official Website:

23 Comments

  1. How can i make data in text file or smthing? Literally i am working at clicker but in replit.

  2. my reset function broke my whole game.i made my reset function like he did, then when i reset, it set everything to nan or undefined and i dont know how to fix it.heres my code. function resetGame() {
    if(confirm("Are you sure you want to reset your game?")) {
    var gameSave = {};
    localStorage.setItem("gameSave", JSON.stringify(gameSave));
    location.reload();
    }
    }

  3. ok so whenever i follow the tutorial, i get to the part where we insert the save game button, and then when i open the game, it says "addToScore is not defined". it IS defined also. i went past this problem and got to the JSON.stringify where we put in the suuuuper long string. it says that the json thingie doesnt work. i cant get past these 2 steps and need to save my game. HELLPPPPP

  4. 6:40iiiif you by any chance still see or read these comments, is there any chance you could explain the point of the "if !== Undefined" bit like I'm 5?

  5. Hello! I'm having a problem, after adding the save mode code, the clicking doesn't function at all, it says "addToScore is not defined", does someone have any idea to fix that? Thank You!

  6. one thing to add is so when you unload the page it will save by doing the following:window.onbeforeunload = function() {
    savegame();
    }

  7. my reset function is a little clunky. sometimes takes 3 attempts to make it work. Any ideas?

  8. the saving or loading does not work and i have typed everything correct

  9. how do you import/export saves as strings of text

  10. Hi! I loved this episode! But there is one problem… The score cannot stay as the score before and I don't know how to fix this.So that means that I can't load the progress… And also, I got a Cannot read property ' ' of undefined error. Is there a way I can fix all of these errors?Also I don't have cookies in my browser. So I can't see the save file.

  11. Do i have to use localhost for the save function to work?

  12. for some reason the save game button doesnt work. i have double checked it like a million times but no. if i just created a random button it would work. the button shows up as text…? <button onclick="saveGame();">Save Game</button>

  13. I don't remember if I missed anything in the previous videos but how do I set up my code to run as a nonlocal file, because whenever I run it it says it's a local file and I can't store cookies

  14. great tutorials.
    for soe reason I'm stuck with the save and it's not working for me, restarts at zero, if you have any idea what I'm doing wrong, please, but I'm sure I'll figure it out. lol

    function savegame() {
    var gamesave = {
    score: score,
    cursorCost: cursorCost,
    cursors: cursors
    };
    localStorage.setItem("gamesave",JSON.stringify(gamesave));
    }

  15. hi thank you for the tutorial!
    i have a problem with the loading, only the score updates when the window loads. everything else is loaded but not displaying on the page
    (if it makes any sense)

  16. What software are you using to host the website on your computer? That is the issue others may be having, since they are just likely loading a HTML page in their browser, not going to a local server to see the HTML page there. It won't let you save a cookie unless you're visiting a 'web server'.

  17. hi! first off, thank you so much for this tutorial series, they're really great! i've been following all the past instructions exactly, but there's one piece of code that messes up the whole thing and i'm not sure why…

    function resetGame() {
    if (confirm("are you sure you want to reset your game")) {
    var gameSave = ();
    localStorage.setItem("gameSave", JSON.stringify(gameSave));
    location.reload();
    }
    }

    everything except for the location.reload() part works just fine, but when i added the last line the game became permanently stuck at the starting variables, and the clicker itself no longer responds. i'm not sure why that one piece causes the whole thing to break, is there any way to fix this? thank you!

  18. the saving and loading isnt working for me it just says "Uncaught TypeError: localStroage.setitem is not a function at savegame"

  19. Its not working cus it thinks im calling a function on this part
    localStorage.setitem

Leave a Reply

Your email address will not be published.