Upgrade Feature not Working

Question:
Whenever I click the upgrade (The image of the purple pointer finger) It should disappear and each cursor should be worth 2 Cycles per Second

Repl link:
https://replit.com/@JohnnySuriano/Cycle-Clicker#index.html


(Purchase Function, might not be useful as I don’t know where the error actually is in the code)

  purchase: function(index) {
    if (game.score >= this.cost[index]) {
      game.score -= this.cost[index];
      this.count[index] += 1;
      this.cost[index] = Math.ceil(this.cost[index] * 1.10);
      display.updateScore();
      display.updateShop();
      display.updateUpgrades();
    }
  }
};

Thanks for any help provided!

I got this error:
Screenshot 2023-08-27 09.42.39

So I think the error is either here:

  purchase: function(index) {
    if (!this.purchased[index] && game.score >= this.cost[index]) {
      if (this.type[index] == 'building' && building.count[this.buildingIndex[index]] >= this.requirment[index]) {
        game.score -= this.cost[index];
        building.income[this.buildingIndex[index]] *= this.bonus[index];
        this.purchased[index] = true;

        display.updateUpgrades();
        display.updateScore();
      } else if (this.type[index] == 'click' && game.totalClicks >= this.requirment[index]) {
        game.score -= this.cost[index];
        game.clickValue *= this.bonus[index];
        this.purchased[index] = true;

        display.updateUpgrades();
        display.updateScore();
      }
    }
  }
};

Line 118:

      if (this.type[index] == 'building' && building.count[this.buildingIndex[index]] >= this.requirment[index]) {

Or here:

let upgrade = {
  name: [
    'Touch Typing'
  ],
  description: [
    'Cursors are now twice as efficient'
  ],
  image: [
    'touchtyping.png'
  ],
  type: [
    'building'
  ],
  cost: [
    '300'
  ],
  buildingIndex: [
    0
  ],
  requirement: [
    1
  ],
  bonus: [
    2
  ],
  purchased: [false],

Try swapping for this.requirement[index]

You have it spelled correctly further up

3 Likes

Annoying it was that simple, but thanks for the help!

2 Likes

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