• Godot Help
  • Can't update this label with a string variable

Greetings. I am encountering a strange issue indeed.

I have a scene called in_game_gui which contains a label node named "messages".
in the scene script, i have created a func to update the label:

func set_message(message: String):
$messages.text = message
$messages/AnimationPlayer.play("flash")

Yes, I am using an animation for a simple blink effect, I know there are tweens. This is not the issue. The issue actually happens even if I comment the last line, so it's not really that problem

My main scene has the in_game_gui scene as a subscene (of a subviewport, to be precise).
Before continuing please take into account that everything else works fine: the in_game_gui has a lot of other stuff that gets updated correctly when I decide to do so, it has signals connected to the main scene and whose funcs are promptly executed when a signal is emitted, etc. etc.

One function in the main scene is responsible to update the message. It has a string contained in a variable. sai "var", and tries to pass it to the in_game_gui dedicated function. And that's what is not working.
That is, when I write:

$info/SubViewport/in_game_GUI.set_message( var)

nothing happens. The label remains empty.

But if I write, say,

$info/SubViewport/in_game_GUI.set_message("pippo")

then the text "pippo" appears when it should.

If i write:
print(var)
then in-run the "output" of godot editor correctly display the text contained in the variable var.

And if I add in the function set_message a line:

func set_message(message: String):
print(message)
$messages.text = message

then also the message "message" is printed correctly. But the text of the label stays empty!
However once again, if I write something like:

func set_message(message: String):
print(message)
$messages.text = "lore ipsum blahblabhblha"

then the text "lore ipsum blahblabhblha" is correctly displayed in the label (and the message is written in the output console of course, as before).

This is driving me crazy. I don't understand what's wrong with passing a String variable, which is always printed correctly with print(), instead of a string constant.
And the problem is indeed PASSING a variable.
Because (last check I did) if I do something like this:

func set_message(message: String):
message = "lore ipsum blablabla"
$messages.text = message

then message is correctly displayed in the text.
So this is really insane, the label text field accepts constants, accepts variables, but DOES NOT accept "passed" variables, altough I have checked that they are passed correctly since they are printed correctly by "print"

    Yes. There could be some trivial mistake, but no one can tell you what it is without seeing a whole project. During the process of making a minimal example, you may discover the mistake yourself.

    nerdino Yes, I am using an animation for a simple blink effect, I know there are tweens.

    Just for good measure, there's also an existing Pulse effect for RichTextLabels

    nerdino blud, what kind of var are you passing in the set_message() funtion?

    Try to cast the var to string in the function:

    func set_massage(massage:String):
    
        var new_val = str(massage)
    
        TextBox.text = new_val
    
    pass

    Ok guys, I think I found the bug, altough I still don't understand what was the problem.

    Another test func that I forgot was setting the text in the label to "".

    After I removed it, everything works. I still don't understand tough, why setting the text to a value passed via a variable variable didn't work while with a constant string it did. I mean, the other function was setting the text to "" anyway, so I shouldn't have ssen anything in any case. Anyway, it's working now. Thank you very much for your trying to help me!