0 votes

I want if a certain button is pressed that the text changes on label / richtextlabel / button, or sprite on sprite / texturerect

in Engine by (43 points)

1 Answer

+1 vote
Best answer

Connect the pressed-signal of your button to a function looking like this:

func _on_Button_pressed():
    $Label.text = "NewText"
    $RichTextLabel.text = "NewText"
    $RichTextLabel.bbcode_text = "NewText"
    $Button.text = "NewText"

    $Sprite.texture = load("res://icon.png")
    $TextureRect.texture = load("res://icon.png")

The node-paths might look different depending on the location of (a) your Button and (b) the Label/RichtTextLabel/Button or Sprite/TextureRect you want to change. In the example I made the (rather unrealistic) assumption that all nodes a click on the Button changes are direct children of the Button-node and their default names are kept.

by (10,249 points)
selected by

Thanks you!!

Is it possible to write text in two strings in this way?
Is it possible to write a var value?

Is it possible to write text in two strings in this way?

$Label.text = "New" + "Text"

Is it possible to write a var value?

var test = "NewText"
$Label.text = test

If the variable's value is not a string, you have to cast the value using str():

var test = 1
$Label.text = str(test)

Is it possible write text in two paragraphs in this way?

$Label.text = "Line1\nLine2D"

The \n is a control character indicate a linebreak. It will be replaced during parsing.

I tried your advice and wrote the command:

$richtextlabel.text = "10/n5/n2"

As a result, I get: 10 / n5 / n2

It's \n, not /n - a backslash.

Ah, got it...

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 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 webmaster@godotengine.org with your username.