0 votes

Hey. I am nearly to a mental breakdown because of this stupid label.
I am processing which character the player is talking to and the name of the character is then displayed as the labels text.
The problem is, that the label doesn't replace the characters name with the new one whenever the following function is called. It adds it to the existing text. For example: At the first call, the labels text displays the characters name and on the second call it doesnt set the entire text new, but it just adds the new text to the old one so that I have the same name two times in the labels text.
I hope you understand my problem now.

Code:

onready var title = get_parent().get_node("HUD/DialogBox/Speaker")   # label
func on_talking(with_who):
    get_parent().get_node("HUD/DialogBox").visible = true
    print("Talking to someone")
    if len(title.text) > 0:
        title.text = ""
        title.text = format_name(with_who)   # format_name only removes "_"
    else:
        title.text = format_name(with_who)
    # some more stuff not related to the label down here
asked Jun 27 in Engine by Frenggie (27 points)

This does sound very frustrating, since the code you've provided seems to me to do what you (and I) expect and want. I think we need more of your project to help diagnose. Can you share it somewhere?

I am sorry but I cannot post the project.
But if it helps diagnosing the problem... there is nothing else which is accessing the labels text property. The function I wrote in my question is in an event_handler.gd script which is running as a child of the player and is called by a signal from the player.

Could it be that Godot is processing common Labels differently in version 3.2.2 ? I am using the steam version.

Thanks for the answer.

I am using 3.2.2 on Mac and having the same issue with Label Node where I have the following code

if playername == "Player1":
    statelabel.text = "Player 1"
else:
    statelabel.text = "Player 2"

The Label shows the 1 and 2 characters overlapping each other ie. the rendered text area is not cleared properly.

Note. I have the same issue with the RichTextLabel

Looks like a 3.2.2 bug to me

Hi adxsoft, please make another question for your issue as the OP has marked this as resolved.

1 Answer

+1 vote
Best answer

Try using the set_text("mystring") function directly without your format_name() function instead of using the property assignment. If that works, try adding back in your function.

If that doesn't work, you could also try the generic set("text", "mystring") function from the base object class.

https://docs.godotengine.org/en/stable/classes/class_label.html?highlight=set_text#class-label-property-text

https://docs.godotengine.org/en/stable/classes/class_object.html?highlight=object#id4

(My assumption is that the problem lies in your format_name() function.)

answered Jun 28 by JimArtificer (699 points)
selected Jun 28 by Frenggie

You're right. Even though the format_name function is basically just iterating over the old name, removing any underscores if there are any and then saves it into a new string und returns that one, it seems to work if I let that out.

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.