Godot Version
v4.3
Question
Hello there! I am currently working on an dungeon crawler operated through a text parser for an university project. I am not that good at programming and I’ve been following a tutorial to set up a text adventure. So far so good - everything works great!
Until I tried to code a “look” command not covered by the tutorial. The idea was that it would output a more detailed description of the room the player currently is in (or a detailed description of anything for that matter)
I set it up exactly the way I set up the basic room description.
>@tool
>extends PanelContainer
>class_name GameRooms
>
>@export var room_name = "Name":
> set(name):
> room_name = name
> $MarginContainer/Rows/RoomName.text = name
>
> @export_multiline var room_description = "Description":
> set(description):
> room_description = description
> $MarginContainer/Rows/RoomDescription.text = description
>
> @export_multiline var room_detail = "Detail":
> set(detail):
> room_detail = detail
> $MarginContainer/Rows/RoomDetail.text = detail
See, the first two, name & description work just fine. The third one I manually added gives me:
Invalid assignment of property or key ‘text’ with value of type ‘Nil’ on a base object of type ‘null instance’.
E 0:00:00:0941 rooms.gd:23 @ @room_detail_setter(): Node not found: “MarginContainer/Rows/RoomDetail” (relative to “PanelContainer”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1792 @ get_node()
rooms.gd:23 @ @room_detail_setter()
Now I double checked the existence of the node (I just copy pasted the RoomDescription label) and the path to it. It exists in the scene and in all other copies of it. I can write in the export variable and the text stays.
If it matters: the function I use to display the text in game is this:
func get_detailed_description() -> String:
return room_detail
And gets called in my GameScript where everything else gets put together too.
Any ideas? Thank you for reading and your help!
1 Like
Can you please send a picture of your scene tree?
2 Likes
Oh of course! My bad!
The scene tree of the scene itself:
![Screenshot 2025-01-08 083251](https://forum.godotengine.org/uploads/default/original/3X/3/1/31679e57c71c328cf488c5490bf2a859204272a9.png)
The scene tree in game (displayed with child nodes):
![Screenshot 2025-01-08 083328](https://forum.godotengine.org/uploads/default/original/3X/f/c/fcee9f8187cc65f6ed5ef7c1f769bf80414136a3.png)
1 Like
I believe this is timing; that is, the properties are set before the scene tree is ready when you run the game. If you were to await ready
in the setter, does this fix it? e.g.
@export_multiline var room_detail = "Detail":
set(detail):
room_detail = detail
await ready # wait for the tree to be ready before changing controls
$MarginContainer/Rows/RoomDetail.text = detail
2 Likes
I tried this aaand it looked promising for a bit but I am getting this error now:
Invalid assignment of property or key ‘text’ with value of type ‘Nil’ on a base object of type ‘Label’.
Also in the game itself the “Room Detail” says “null” now. The text I used to put in there used to show up, now it keeps showing null, even though the text has changed. In the scene itself it still says my default text.
Yep, for sure - other controls may also be affected by the same issue; I simplified it to just the labels shown here. Also, because this is a tool
script, you will need some extra logic to set it in the editor versus at runtime where you might need to wait for ready
. See here: Running code in the editor — Godot Engine (stable) documentation in English
I’d imagine something like this:
@export_multiline var room_detail = "Detail":
set(detail):
room_detail = detail
if not Engine.is_editor_hint():
await ready # wait for the tree to be ready before changing controls
$MarginContainer/Rows/RoomDetail.text = detail
Give or take.
1 Like
Thank you very much for your help!
Now I’ve read through the documentation and tried several things. In the end I ended up with errors in other places and decided to pick this workaround:
Instead of trying so hard to implement the label with a description solely accessed by a command anyway, I decided to scrap the label altogether.
@export_multiline var hidden_description: String = "Look Command"
Now this is what I ended up with. I can set my descriptions and I can access them with the look command and my game doesn’t nuke itself in red error messages!
1 Like