Jump to content

forEach undefined


Recommended Posts

Hello again,

I'm having difficulties getting a particular section of my code to cooperate.

I have some abilities that go on cooldown after use and I would like to have a feature that allows you to reset their cooldowns, however I believe I'm running into a lack of understanding issue.

The shop button is supposed to execute the resetAbility function on all of the buttons within the abilitiesButtons group, however it's generating "Uncaught TypeError: Cannot read property 'forEach' of undefined" when the button is pressed.


this.abilitiesPanel = this.game.add.image(1565, 10, this.game.cache.getBitmapData('abilitiesPanel'));
        var abilitiesButtons = this.abilitiesPanel.addChild(this.game.add.group());

        var abilitiesButtonsData = [
            //this is where the abilities are

onShopButtonClick: function(shopButton, pointer, player) {
            if (shopButton.details.name == 'Reset Cooldowns'){
                this.player.Jewels -= shopButton.details.cost;
                this.shopButtonsText.text = "Jewels: " + this.player.Jewels, {font: '14px Arial Black'};
                abilitiesButtons.forEach(function(abilitiesButtons) {

    resetAbility: function(abilitiesButton) {
        abilitiesButton.inputEnabled = true;
        abilitiesButton.alpha = 1;


I'm certain I'm misunderstanding how to get the shop button to reference the buttons within the abilitiesButton group (as they're both in separate groups), but if anyone could shed some light on this issue for me I'd be grateful.


Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...