–1 vote

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 entertree():
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.addchild(psnBtn)
$BattleSceneCanvas/EnemyStuff/StatusGrid.add
child(bleedBtn)
$BattleSceneCanvas/EnemyStuff/StatusGrid.add_child(stunBtn) #testing purposes

func func _process(delta):
statusButtonHover()

func statusButtonHover():
if(psnBtn.ishovered()):
$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!

Godot version 3.4.4
in Engine by (11 points)

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.

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.