Hi, I’m trying to send text to a label to change the character’s (FemaleCharacter) level when they level up and I’ve done it right the first time but it is giving me this error now that I tried again:
[Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘null instance’.]
I tried making it unique and dragging it to the code, @ready-ing it, get_node()… but I couldn’t find in the documentation more than text and set_text()… I’m new and getting desperate with no idea of what is wrong except for it probably has something to do with the label being in the CanvasLayer tree and not the FemaleCharacter tree. Can someone please help me understand and fix this?
To node FemaleCharacter, add the following line of code under extends CharacterBody2D:
signal level_up(new_level : String)
This defines something called a signal; something you can use to communicate data between scenes without one scene having to know information about the other.
Click on the Home node. On the right side of your screen, the inspector should appear. Drag the Player_Level node to the new Player Level Node field in the inspector. What this does is make the Home node capable of accessing the Player_Level node’s internals.
In _ready, you’re connecting method _on_level_up to signal level_up. We can choose to emit the signal, and when we do, the connected method will now execute.
Now all we need to do is emit the signal. You can do this from within any method inside Player_Level like this:
Thanks, this worked very well! I even tried to use a signal before but did it the wrong way, for some reason I have a hard time understanding how this particular mechanic works because it goes through a lot of places but I’ll get there.
Also I would like to point out that noob me was using the signal in a child node of the FemaleCharacter and I only today discovered that there are some child nodes that don’t enter the tree so they don’t get called (thank you Godotneers). I think this was also part of my problem so if anyone else is doing the same mistake I hope you find this and get over it quicker than I did. hahaha
I wish you have a great week and no errors in your code. Lots of love.