- Edited
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"