Godot Version
4.6.3
Question
I’ve been working on translating a pyGame project I did for school into something that was more what I had imagined it to be (if I weren’t limited to school specific functions). The frustrating thing is, is this was working. Then it stopped and kept giving me errors or crashing the debug as in the debug is hung up.
I have an Array of Dictionaries that I am try to access to change a RichTextLabel. This worked just fine both in having the array in the main script and in a seperate Resource. I wanted to utilize Resources so that I wasn’t cluttering up the main code, but after a few hours and a break, I came back to my resources suddenly emptied after reloading my project, and suddenly not working when I fix them. Each time I try to access it, it returns Cannot Access because base type ‘Nil’.
Maybe somewhere I’ve mis-typed something, or forgot something specific and I’m too frazzled by this to realize it. I’m hoping a second set of eyes can at least help me see what, where, has decided to flip itself and cause the whole thing to either hang or throw an error and crash.
extends Resource
class_name MainRoomData
@export var stable_info: Array[Dictionary] = [
{
"name": "Forest",
"start": "????",
"exit": {
"north": "keyword for exit"
},
},
{
"name": "end",
"exit": {
"north": "keyword for exit"
}
},
{
"name": "exit",
"exit": {
"north": "keyword for exit"
}
}
]
# this is the code from my main scene
extends Control
var current_room := 0
@export var room_details: MainRoomData
@onready var label: RichTextLabel = %Label
func room_text() -> void:
var room = room_details.stable_info[current_room]
label.text = room["start"]
# this is consistantly returning Invalid access to property or key 'stable_info' on a base object of type 'Nil'
Is your exported variable assigned? What does your Inspector say for this control node? You may have to check in the scene itself and anywhere it is instantiated.
The control node script is what I am launching the scene from currently. That control node is the parent to the RichTextLabel and several other variables. I thought my exported variable is assigned? Is that not what adding it to the main script does? I mean, I have also tried adding in
var game_room = room_details
and then adjusting the rest of the room_text() function, but it once again gives me the error about Nil. So perhaps what I need to understand is what is meant by the exported variable being assigned? Is it not assigned in the above code? Have I completely misunderstood that and done something that mysteriously worked, and then somehow I removed said something and completely messed with the entire thing without realizing it?
Sorry I’m exhausted right now and half-falling asleep.
Edit: to clarify in the initial post the top portion that extends Resource I have used as both creating a resource object and then just hardwriting the code. Both results result in the Nil error despite previously working a few hours prior to this issue.
The script being attached does not assign the export variable to anything on it’s own. Exported variables appear in the Inspector like other properties, you will assign the resource in that panel.
…..I am an idiot and being half-asleep isn’t helping. I completely forgot about that. I’m gonna guess that it got somehow reset when my whole project reset several things in the Inspector, and in my confusion and exhaustion I forgot about it entirely.
Not idiot, it’s quite trippy and forgetting is an important part of learning. There are some odd bugs in the engine that do reset exported variables, adding a type seems to mitigate most of the issues I’ve seen. Renaming exported variables will always reset them too, so watch out for that.
# Not typed, due to a bug may end up being <null>
@export var my_export = 123
# int typed, will never be <null>
@export var my_export: int = 123