Bazgir Posted February 9, 2017 Share Posted February 9, 2017 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()); abilitiesButtons.position.setTo(10,0); 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(); }); } }, 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. Thanks Link to comment Share on other sites More sharing options...
samme Posted February 9, 2017 Share Posted February 9, 2017 2 hours ago, Bazgir said: "Uncaught TypeError: Cannot read property 'forEach' of undefined" It's telling you (undefined).forEach(function(abilitiesButtons) { // … Link to comment Share on other sites More sharing options...
Bazgir Posted February 11, 2017 Author Share Posted February 11, 2017 Thank you for the reply. I managed to figure out the issue, but ended up rewriting quite a few things so it no longer appears the same. Link to comment Share on other sites More sharing options...
Recommended Posts