Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ExpNeeded |
Here is the script
func ButtonVisible():
if phraseNum <= 3:
$“…/Next”.visible = 1
else:
$“…/Next”.visible = 0
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ExpNeeded |
Here is the script
func ButtonVisible():
if phraseNum <= 3:
$“…/Next”.visible = 1
else:
$“…/Next”.visible = 0
Reply From: | godot_dev_ |
If I understand the question correctly, you want a button’s visibility to be conditional based on some variable’s value?
You could achieve it as follows.
visibilityCondition
visibility_value_changed
, where that signal is emitted any time your variable is changed_on_visibility_value_changed
in your button script that will perform the visibility check to decide whether your button should be visible or invisibleSee example code below:
#Script, button.gd
export (int) var visibilityCondition=3
func signalConnect(your_emitter):
your_emitter.connect("visibility_value_changed",self,"_on_visibility_value_changed")
func _on_visibility_value_changed(phraseNum):
if phraseNum <= visibilityCondition:
self.visible=true
else:
self.visible=false
Make sure a node higher in the scene tree connects the node/script that emits the visibility_value_changed
, lets name the node/script node1
to the button by calling button.signalConnect(node1)
, where button
is the button you want to toggle the visibility