0 votes

I've tried update() in various places, and I've confirmed via the console that both update() is called and that the changes I want to see in the RichTextLabel are happening in the code, but I just can't get the label to update visually.

RichTextLabel doesn't seem to have a method other than update() for this purpose. I've been to the Godot discord for help, and we couldn't determine why updating the label's text field(s) wouldn't cause the thing to simply update visually as well, and as such the solutions we tried were both indirect and ineffective.

The code to update the label's text does run once - during initiation, in the ready() method, which calls a method I created which simply calls clear() and adds new text via add_text(). Calling that same update method outside the does nothing, however, so my assumption is something somewhere is caching the drawn label and I'm failing to trigger a redraw. That or something unrelated, so I've included the project here:

https://drive.google.com/file/d/11v3duA3V1QTvJNT6ToOETlWVxeMSiaSv/view?usp=shar

Edit: And thank you to anyone who attempts to help with this problem, whether if it's very obvious or one that stumps us all.

Godot version 3.2.1
in Engine by (26 points)
edited by

I'm not sure if this answers your question, but all you need is to update/change your text, right?
Well then you could simply alter the text like this:

$RichTextLabel.text = "Updated Text"

Also, I never even knew there was an update() function for RichTextLabels. I've always used this method.

Another method is to use the set_text() function. Like the function above, it will replace whatever was once on the label when you call it.

$RichTextLabel.set_text("Updated Text")

I opened your project and added this to the top of the Stats.gd script:

func _input(event):
    if event.is_action_pressed("ui_accept"):
        var c_scene := get_tree().current_scene
        var stat_panel: RichTextLabel = c_scene.find_node("stat_panel")
        assert(stat_panel)
        stat_panel.add_text("!")

Every time I hit Enter, it adds an exclamation mark as expected.
Tested in 3.2.3 and 3.2.4 RC2.

I searched your code, and didn't see any text = ... or add_text(...) in any scripts other than StatPanel.gd, so I don't know where or how you were attempting to change the text. add_text() is working perfectly fine for me.

I used your comment to help me work toward what was wrong - i was trying to use methods and objects and so on that didn't exist yet; programming as if everything simply poofed into existence simultaneously

1 Answer

0 votes
Best answer

The reason my code wasn't working is because I was trying to use objects that weren't initialized yet.

by (26 points)
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.