I want to fix an upgrade with localstorage

I want to make the “clicking upgrades” save in local storage. I got help previously, but it doesn’t work really :grimacing:. https://replit.com/@BluebayStudios/Ples-nerd The upgrades are under “clicking upgrades”

1 Like

Can you be more specific?

When you try to save is giving any errors? What is the proccess to save the upgrades?

Looking your various buyItem functions is making my OCD go wild, there is a way to refactor them into a single function that takes the item type or price as parameters (so you have only one function that takes the item price and the increment value for upgradeCount as parameters which can handle the common logic of all your item purchases)

Also it will be much more easier to add new items in the future, as you only need to add new calls to buyItem.

1 Like

There are no errors, they just don’t save after refreshing.

I just noticed something, in your buyExtraFinger , buyExtraHand , buyExtraPerson , and other functions like that where you modify the npc variable, you need to save the updated npc value to local storage, just like you do with nerd and upgradeCount .

I think that may be the problem.

1 Like

So how is this able to be fixed? It’s really bothering me :grimacing:

Like you’ve been doing with the others

function buyExtraFinger(price) {
  if (nerd >= price) {
    nerd -= price;
    npc += 1; // Increase npc
    updateScore();
    localStorage.setItem("nerd", nerd); //You already do it here
    localStorage.setItem("npc", npc); // Just make the same to the npc
  } else {
    alert("you don't have enough nerd to buy this item");
  }
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.