Bazgir Posted February 7, 2017 Share Posted February 7, 2017 Hello, I'm a little new to phaser and at the moment I'm having difficulties getting a button to have a cooldown. More or less, you click it and it executes its purpose and disables itself, however I'm trying to get the input to be enabled after a timer and this is where it's falling apart for me. When I check, it's telling me "Uncaught ReferenceError: abilitiesButton is not defined" for line 651, which relates to the "abilitiesButton.inputEnabled = true;" as listed below. 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,10); var abilitiesButtonsData = [ {icon: 'homebutton', name: 'Chill Out', cost: 10, purchaseHandler: function(abilitiesButton, player) { player.Paranoia = 0; this.playerParanoiaText.text = 'Paranoia: ' + this.player.Paranoia; }}, ]; var abilitiesButton; abilitiesButtonsData.forEach(function(abilitiesButtonData, index) { abilitiesButton = state.game.add.button((100 * index), 0, state.game.cache.getBitmapData('abilitiesButton')); abilitiesButton.icon = abilitiesButton.addChild(state.game.add.image(0, 0, abilitiesButtonData.icon)); abilitiesButton.details = abilitiesButtonData; abilitiesButton.costText = abilitiesButton.addChild(state.game.add.text(10, 10, 'Cost: ' + abilitiesButtonData.cost, {font: '14px Arial Black'})); abilitiesButton.events.onInputDown.add(state.onAbilitiesButtonClick, state); abilitiesButtons.addChild(abilitiesButton); }); onAbilitiesButtonClick: function(abilitiesButton) { abilitiesButton.details.purchaseHandler.call(this, abilitiesButton, this.player); abilitiesButton.inputEnabled = false; var reduceParanoiaCooldownTimer = this.game.time.events.add(1000, this.resetAbility, this); }, resetAbility: function() { abilitiesButton.inputEnabled = true; }, Does anyone have an idea as to what I'm doing wrong to get it to properly enable input on the pressed button after X amount of time? Thanks Link to comment Share on other sites More sharing options...
samme Posted February 8, 2017 Share Posted February 8, 2017 There's no reference to `abilitiesButton` at that point. You can pass it through the timer event handler: onAbilitiesButtonClick: function(abilitiesButton) { // … var reduceParanoiaCooldownTimer = this.game.time.events.add(1000, this.resetAbility, this, abilitiesButton); }, resetAbility: function(button) { button.inputEnabled = true; }, Link to comment Share on other sites More sharing options...
ldd Posted February 8, 2017 Share Posted February 8, 2017 samme is right but I guess they meant there is no `button` being passed to `resetAbility`. Basically, you didn't give any parameters to `resetAbility`. Link to comment Share on other sites More sharing options...
Bazgir Posted February 8, 2017 Author Share Posted February 8, 2017 Thank you both for your responses, that solved my issue perfectly! Link to comment Share on other sites More sharing options...
samme Posted February 8, 2017 Share Posted February 8, 2017 Oops I meant no reference to `abilitiesButton` in `resetAbility`. The code is right. Link to comment Share on other sites More sharing options...
Recommended Posts