How to use a button press to set the text of a RichTextLabel and show it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By scovelme
:warning: Old Version Published before Godot 3 was released.

What I want to happen is when you click a button, it sets the text of a RichTextLabel and makes it visible. Here is my code:

extends TextureButton

# member variables here, example:
# var a=2
# var b="textvar"

func _ready():
	set_process(true)

func _input(event):
	if(Input.is_mouse_button_pressed(BUTTON_LEFT)): _flumpterado()


func _on_CarCheck_toggled( pressed ):
	get_parent().get_parent().get_node("KinematicBody2D").get_node("AnimatedSprite").get_node("CheckPanel").get_node("CheckText").set_bbcode("My car. Nothing more, nothing less.")
	get_parent().get_parent().get_node("KinematicBody2D").get_node("AnimatedSprite").get_node("CheckPanel").get_node("CheckText").show()

func _on_CarCheck_pressed():
	get_parent().get_parent().get_node("KinematicBody2D").get_node("AnimatedSprite").get_node("CheckPanel").get_node("CheckText").set_bbcode("My car. Nothing more, nothing less.")
	get_parent().get_parent().get_node("KinematicBody2D").get_node("AnimatedSprite").get_node("CheckPanel").get_node("CheckText").show()
func _flumpterado():
	get_parent().get_parent().get_node("KinematicBody2D").get_node("AnimatedSprite").get_node("CheckPanel").get_node("CheckText").set_bbcode("My car. Nothing more, nothing less.")
	get_parent().get_parent().get_node("KinematicBody2D").get_node("AnimatedSprite").get_node("CheckPanel").get_node("CheckText").show()

But the problem is: When I click the button, nothing happens. I don’t know if the RichTextLabel is not becoming visible for some reason, or if the button is not acknowledging the click, or what. But I need help solving it.

Edited to make the code more readable (hint: you have to add 4 spaces before each lines for the code to appear formatted).

Zylann | 2016-11-10 20:31

:bust_in_silhouette: Reply From: Zylann

Did you connected the pressed signal from the button to your function? Writing the function is not enough to make it detected.
Also, if you want to use _input(), you have to enable it by calling set_process_input(true).

I also strongly recommend you to put the RichTextLabel you want to set in a variable, so your code will be a lot more readable and efficient:

extends TextureButton


onready var richtext = get_parent().get_parent().get_node("KinematicBody2D/AnimatedSprite/CheckPanel/CheckText")


func _ready():
	set_process_input(true)


func _input(event):
	if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
		_flumpterado()


func _on_CarCheck_toggled( pressed ):
	richtext.set_bbcode("My car. Nothing more, nothing less.")
	richtext.show()


func _on_CarCheck_pressed():
	richtext.set_bbcode("My car. Nothing more, nothing less.")
	richtext.show()


func _flumpterado():
	richtext.set_bbcode("My car. Nothing more, nothing less.")
	richtext.show()