Issues when Creating Buttons in Script and Hovering Over Them

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BradsGaming

So essentially I am creating status effects, when a button comes up I then want to be able to hover over the button to show what the status effect does. I got it to work for 1 button but when I add more buttons to the container the newest button seems to be the only one to show in the label. Though when I trouble shoot the .is_hovered() buttons they print to the console so it is strange.

var psnBtn = Button.new()
var bleedBtn = Button.new()
var stunBtn = Button.new()

func _enter_tree():
psnBtn.icon = load(“res://Sprites/PoisonIcon.png”)
psnBtn.flat = true
bleedBtn.icon = load(“res://Sprites/BloodIcon.png”)
bleedBtn.flat = true
stunBtn.icon = load(“res://Sprites/StunIcon.png”)
stunBtn.flat = true
$BattleSceneCanvas/EnemyStuff/StatusGrid.add_child(psnBtn)
$BattleSceneCanvas/EnemyStuff/StatusGrid.add_child(bleedBtn)
$BattleSceneCanvas/EnemyStuff/StatusGrid.add_child(stunBtn) #testing purposes

func func _process(delta):
statusButtonHover()

func statusButtonHover():
if(psnBtn.is_hovered()):
$BattleSceneCanvas/statusLabel.text = “Poisoned, Take 1 Dmg Until Cured!”
$BattleSceneCanvas/statusLabel.visible = true
else:
$BattleSceneCanvas/statusLabel.visible = false
if(bleedBtn.is_hovered()):
$BattleSceneCanvas/statusLabel.text = “Bleeding, Take %d Dmg at the Start of the Next Turn” % (round(player.getAtk() * .25))
$BattleSceneCanvas/statusLabel.visible = true
else:
$BattleSceneCanvas/statusLabel.visible = false
if(stunBtn.is_hovered()):
$BattleSceneCanvas/statusLabel.text = “Can’t Attack for 1 Turn”
$BattleSceneCanvas/statusLabel.visible = true
else:
$BattleSceneCanvas/statusLabel.visible = false

I feel like this is pretty straight forward just not sure what I am missing. Thanks in advance!

It’s difficult to say because of the code formatting, but is it because your last button, in the last “if”, is setting the label visibility to false if it’s not hovering, thus hiding it even if another button is being hovered? I would only set the label visibility to false before all the "if"s, and then set it to true if required by any of the buttons.

SteveSmith | 2022-10-02 08:11

That did work, I knew it was something simple I just added an if that checks if all of the buttons are not hovered then set visibility to false.

BradsGaming | 2022-10-03 14:21