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

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:


  1. for some reason, one of my auto upgrades won’t load even though i put all the right lines of codes

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

  3. It Won't load :(//LoadGamefunction loadGame(){ var savedGame = JSON.parse(localStorage.getItem("saveGame")); if (typeof savedGame.score !== "undefined") score = savedGame.score; if (typeof savedGame.clickpower !== "undefined") cpc = savedGame.clickpower; if (typeof savedGame.cps !== "undefined") cps = savedGame.cps; if (typeof savedGame.cursorCost !== "undefined") cursorCost = savedGame.cursorCost; if (typeof savedGame.cursors !== "undefined") cursors = savedGame.cursors; if (typeof savedGame.grandmaCost !== "undefined") grandmaCost = savedGame.grandmaCost; if (typeof savedGame.grandmas !== "undefined") score = savedGame.grandmas; if (typeof savedGame.staminaCost !== "undefined") staminaCost = savedGame.staminaCost; if (typeof savedGame.stamina !== "undefined") stamina = savedGame.stamina;}(Stamina boosts click power)

  4. I have a 45-line JS file that can do part 3.

  5. PLEASE HELPPPPP. I did the reset to test it and it destroyed my whole game what do I do.

  6. I'm having some trouble with the saving. It wont let me add to my score when I click and if I try to see why, it just shows addToScore is not defined. Here is the code where it has the glitch<img src="images/bluecircle.png" height="256px" width="256px" onclick="addToScore(clickingPower)"> I cannot find (at least) nothing wrong with it but maybe I'm wrong. Most likely. Anyways, does anyone know what to fix? Have a nice day!

  7. I saw your new game trailer for Noslrac, I was wondering if maybe you would read this but when I set the cookie and i press the info button, it just says your on a local file or shared file. Do you know why?

  8. 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));

  9. 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

  10. 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?

  11. 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!

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

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

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

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

  16. 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.

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

  18. 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>

  19. 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

  20. 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

  21. 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)

  22. 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'.

  23. 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));

    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!

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

  25. Its not working cus it thinks im calling a function on this part

Leave a Reply

Your email address will not be published.