Invalid assignment of property or key 'text' with value of type 'String' on a base object of type 'String'.

Godot Version

v4.6.1.stable.official

Question

Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘String’.

Getting this error in a fairly straightforward area of my code, haven’t run into many issues regarding labels, and not seeing the same example of “object of type ‘String’.”

The UI node is a Label, the scene exists at the time of calling the script below - just before updating the label I set up a progress bar in the same area.

Relevant code:

extends Control

@onready var questLbl = $(scene ref)

func _on_quest_btn_pressed() → void:
   var questData = rmgr.GetQuest(charLv)
   #set progress bar with quest time info
   InitQuestLbl(questData[NUMREF.ONE])

func InitQuestLbl(output: String):
   questLbl.text = output

---

func GetQuest(level: int):
   #total time, quest text, reward type, reward amount
   var questData = []
   #get/set quest time
   #get/set quest text string ***
   #get/set reward type
   #calculate reward amount
   return questData

#***confirmed in debug this is pulling the expected test text string

Please let me know if I’m missing anything or should provide more details, but I believe this is every piece that touches the data before it errors when trying to set questLbl.text = output

Somehow your questLbl is a string, not a node, are you sure this variable is set correctly? What does the actual code read?

You could also add a static type (such as Label) to questLbl in case you are accidently setting it to a string later.

@onready var questLbl: Label = $YourLabelPath
1 Like

Thank you for the information, I’ve never really hit a hard block on a label type so that’s interesting!

Full line for the reference reads:

@onready var questLbl = $PaddingBox/ProgressBar/QuestLbl

Hovering over QuestLbl in the Scene Tree does confirm Type: Label, but I can try and static type it this time and see if that works.

Shoot, I realize my mistake now - in the ready code I call a scene reset to make sure default variables are what I expect. But of course forgot the ‘.text’ there, causing the label to re-ID itself as a string (questLbl = "“ vs questLbl.text = ““).

Thank you nonetheless!

Yeah that’s something adding static types will help catch!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.