I am getting a crash in my code that I can’t figure out, the error is as follows:
“Invalid set index ‘text’ (on base: ‘null instance’) with value of type ‘String’.” which I thought I avoided by already having @onready with my variables.
Here’s the code that’s going wrong:
#text variables @onready var food_text: RichTextLabel = $Control/Resources/FoodText
Here’s a screenshot of my editor/scene tree. Yes I know this isn’t the most efficient way to display text, but I’m doing it for style reasons. And unless I’m missing something obvious, it should still work
i tested similar scene tree and codes, even without the await get_tree().physics_frame, it’s already working, your update_stats() could be accessed somewhere where the node not even ready
No other part of the script is calling update_stats() at the start of the game. I’m more than a little baffled because my setup looks just like what you’re doing but I’m getting thrown an error no matter what
yeah that’s strange, so accessing the update_stats() function will just result in crashing, what happen if you put the food_text.text= line to the bottom-most of update_stats()?
When I use @export, I get this error:
Parser Error: The default value is using “$” which won’t return nodes in the scene tree before “_ready()” is called. Use the “@onready” annotation to solve this. (Warning treated as error.)
to use @export, do it like this @export var food_text:RichTextLabel
then click the TheRoom Node, you will see Food Text variable exposed in the Inspector dock, click drag and drop the FoodText RichTextLabel to the Food Text in the Inspector dock, that’s how you assign the FoodText Node with @export
show the already assigned food_text variable in the inspector dock btw, if it’s true you already assigned, with await for like 3 seconds, then something really wrong with your editor