Weird Variable Naming Error ~it wont work with a specific name but will work any other~

Godot Version

Godot_v4.3-stable_win64.exe

Question

tldr: variable naming of open_seq doesn’t work but open_seqs works???
So I have a main script that runs the main game and in it, i’ve preloaded the TRES file

var text = preload("res://resources/Dialogues.tres")

The dialogue script contains arrays of dictionaries, each line of array containing a dialogue with the corresponding expression the characters will show while the dialogue appears in the text box.

@export var cas_dict = [
		{"sbj":"Her","dlg": "Casual Dialogue Test Line 1 #1", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony},
		{"sbj":"Her","dlg": "Casual Dialogue Test Line 1 #2", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony}, ]

etc
While i was editting, somewhere in between i may have made an error which i thought was not a big deal. But when I tried to run my game again, for some reason my code breaks on the main script on lines like these:

var event = text.event_arrays[values.enc_events]
chosen = text.cas_dict[randi_range(0,2)]

All with the same error of:
invalid access to property or key on a base object of type nil

This made me panic, as my game had worked normally beforehand.
But after a while of panicking i tried to change the variable’s names on both ends (on the main script and the dialogue script)

cas_dict → cas_dicts
event_arrays → event_arrayss

and my game worked again! I tried closing my game and changing the variable’s name back to its original name but the same error was output.

I’m looking to reverse the error because I simply do not like the naming scheme of “arrayss” and “cas_dicts” and “open_seqs”. These are the suspicious things i might’ve done that broke my script:

  • while streaming to my friend, i dragged the dialogue.gd script around and into the dialogue.tres file in the “FileSystem” tab
  • he told me to do either of these: shift+n , shift+ctrl+n, shift+tab, ctrl+tab while a certain portion of the dialogue.gd script was selected thinking it would tab the whole section forward once (i’m a noob coder and he doesn’t use godot but other languages idk specifically which)

Is there any way to fix this.
Thank you in advance for bothering to read <3

Tab and Shift + Tab are all you need in the Godot editor to indent everything selected, or conversely un-indent it.

I recommend you don’t ask advice from someone who doesn’t actually know GDScript and Godot.

Shouldn’t have done anything, but again, don’t take advice from people who don’t know the language and IDE. Both are specialized, and as someone who has used many other languages and IDEs, I can tell you a lot of advice you’re going to get from professional programmers without context of Godot and GDScript is going to be misleading and confusing.

This is all weird. Having said that, your variable names are very confusing. There is no reason to abbreviate names. In fact, spelling things out, like variable names makes your code clearer. It certainly helps when you’re pasting it here and we are trying to help you.

While we are on the subject, there is no reason to put the type of a variable as part of the variable name. I’d recommend renaming them events, cases (or whatever that is), and open_sequences.

This likely has to do with a race condition if it works by changing the variable name. Either that, or you have naming issues somewhere else. It would be helpful if you could paste your entire script here. Regardless, changing the name to add an ‘s’ is a red herring.

1 Like

Thanks for the advices! I’ll keep an eye out next time with what my friend suggests me to do. I’ve had success a few times beforehand consulting him thus my trust in asking him. As for the error, I practically have done nothing to the project this last hour, figuring out what’s wrong and right now
the naming scheme with the added “s” wont work but the original variable names work.. I really don’t know anymore. Maybe my Godot is freaking out but I have tried closing and reopening as I’ve mentioned before but the error for a specific names for each arrays still persist.

As for the Dialogue.tres file, the arrays in its properties are shown as (Nil) even though it is full of lines. The array format of the green censored variable is exactly the same as the others, yet for some reason it shows as Array (size 2) instead of (Nil). This has been the case ever since before this error even occurred and yet the game had run without issues.

a section from the dialogue.gd script:

@export var event_arrays = [
	{"love_req": 0, "day_req": 0, "mood_req": 0, "hour_req": 0, "love_giv": 2, "mood_giv":5, "hour_skip":0,
	"dialogue_array": [
		{"sbj":"You","dlg":"Do you mind telling me what happened?", "eyes":eyes_closed_brows_up, "mouth":mouth_open_o, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"I.. got fired from my job", "eyes":eyes_sideeye, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"I made a major mistake at work and they decided to fire me for it", "eyes":eyes_closed_brows_up, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"My workplace was supposed to pay for my rent but since I got fired I had nowhere else to go..", "eyes":eyes_closed_brows_down, "mouth":mouth_frown, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"I got by with the money I had left staying at a manga cafe", "eyes":eyes_closed_brows_down, "mouth":mouth_frown, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"But I ran out of funds after a few days", "eyes":eyes_closed_brows_down, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"I had nowhere else to go and I was hesitant but eventually I decided to ask you for some help", "eyes":eyes_closed_brows_down, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"And here I am now", "eyes":eyes_closed_brows_down, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"dlg":""}
	]
	},
	{"love_req": 0, "day_req": 1, "mood_req": 0, "hour_req": 0, "love_giv": 2, "mood_giv":5, "hour_skip":0,
	"dialogue_array": [
		{"sbj":"You","dlg":"Here, I thought you could use these.", "eyes":eyes_default, "mouth":mouth_frown, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"Clothes?", "eyes":eyes_default, "mouth":mouth_open_o, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"You","dlg":"They're my sister's.", "eyes":eyes_default, "mouth":mouth_frown, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"You","dlg":"She makes me keep some clothes for her so she doesn't have to bring too much baggage whenever she visits", "eyes":eyes_default, "mouth":mouth_frown, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"I have to thank your sister too then", "eyes":eyes_closed_brows_up, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"I'll try them on", "eyes":eyes_default, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"You","dlg":"Eh, now?", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"Turn around for a sec.", "eyes":eyes_default, "mouth":mouth_open_smile, "blush":true, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": true},
		{"sbj":"You","dlg":"...", "eyes":eyes_default, "mouth":mouth_open_smile, "blush":true, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": false},
		{"sbj":"Natsume","dlg":"So..", "eyes":eyes_default, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_office_shirt,"hair":hair_pony,"girl": false},
		{"sbj":"Natsume","dlg":"So.. How do I look?", "eyes":eyes_default, "mouth":mouth_open_smile, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_home,"hair":hair_pony,"girl": true},
		{"sbj":"You","dlg":"I'm glad it fits?", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_home,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"Geez..", "eyes":eyes_default, "mouth":mouth_open_o, "blush":true, "sorrow":false,"sweat1":true,"clothes":clths_home,"hair":hair_pony,"girl": true},
		{"sbj":"You","dlg":"..?", "eyes":eyes_default, "mouth":mouth_open_o, "blush":false, "sorrow":false,"sweat1":true,"clothes":clths_home,"hair":hair_pony,"girl": true},
		{"dlg":""}
	]
	},
	{"love_req": 9, "day_req": 2,  "mood_req": 0, "hour_req": 0, "love_giv": 0, "mood_giv":0, "hour_skip":0,
	"dialogue_array": [
		{"sbj":"Natsume","dlg":"I'd like to thank you again for letting me stay", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"It's been a couple days already..", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths,"hair":hair_pony,"girl": true},
		{"sbj":"Natsume","dlg":"I feel like I'm a bother, so I'll try to get out of your hair as soon as possible", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths,"hair":hair_pony,"girl": true},
		{"sbj":"You","dlg":"...", "eyes":eyes_default, "mouth":mouth_smile, "blush":false, "sorrow":false,"sweat1":false,"clothes":clths,"hair":hair_pony,"girl": true},
		{"dlg":""}
	]
	}
]

@export var ###_seq = [
	{"love_req": 0, "day_req": 0, "mood_req": 0, "hour_req": 0, "love_giv": 0, "mood_giv":0, "hour_skip":0, "###_event":0,
	"dialogue_array": [
		{"sbj":"You","dlg":"#########"},
		{"dlg":""}
		]},
	{"love_req": 0, "day_req": 0, "mood_req": 0, "hour_req": 0, "love_giv": 0, "mood_giv":0, "hour_skip":0, "###_event":0,
	"dialogue_array": [
		{"sbj": "You","dlg":"########"},
		{"dlg":""}
		]}]

a section from the main.gd script:

func _on_casual_pressed() -> void:
		var event = text.event_arrays[values.enc_events]
		if values.love >= event.get("love_req") and values.day >= event.get("day_req") and values.mood >= event.get("mood_req"):
			chosen = event.get("dialogue_array")
			values.enc_events += 1
			$Girl/Eyes.texture = chosen[line].get("eyes")
			$Girl/Mouth.texture = chosen[line].get("mouth")
			$Girl/Blush.visible = chosen[line].get("blush")
			$Girl/Sorrow.visible = chosen[line].get("sorrow")
			$Girl/Sweat1.visible = chosen[line].get("sweat1")
			$Girl.visible = chosen[line].get("girl")
			clothes_func(chosen[line].get("clothes"))
			hair_func(chosen[line].get("hair"))
			values.love += event.get("love_giv")
			values.mood += event.get("mood_giv")
			values.hour += event.get("hour_skip")

		else :
			chosen = text.cas_dict[randi_range(0,2)]
			values.love += randi_range(2,4)
			values.mood -= randi_range(1,3) * double
			$Girl/Eyes.texture = chosen[line].get("eyes")
			$Girl/Mouth.texture = chosen[line].get("mouth")
			$Girl/Blush.visible = chosen[line].get("blush")
			$Girl/Sorrow.visible = chosen[line].get("sorrow")
			$Girl/Sweat1.visible = chosen[line].get("sweat1")
			clothes_func(chosen[line].get("clothes"))
			hair_func(chosen[line].get("hair"))

basically if an event requirement is fulfilled clicking casual button will play an event, but if there are no even requirements fulfilled it will instead play the casual dialogues

I’m aware there are a lot of improvements to be made but my issue right now is still that variable naming problem

As of the end of typing this, I’ve literally not touched my project, and it has gone back to anything but the correct names NOT working.

edit: imma try restarting my computer..

Same problem persist after restarting. I really don’t have a clue.

what i’ve found and what the current problem is:

  • Changing the name fixes it and the game runs normally
  • Leaving the engine run for a bit will make the current change to the name broken again thus needing to rename the variable again.

Hard to follow along, can you post the exact error, and the script it comes from, pointing out which line exactly the error comes from?

I FOUND IT

  • Changing the variable name fixes it and the game runs normally
  • Editing any of the arrays in the tres file from the inspector and undoing any change with the undo button makes every exported variable in the script, except for the green censored one, to break. which leads me to renaming it to work again.

    Idk what is it that i have to fix so that it wont break but i feel like there has to be something to do with how none of the other exported array variables are like the green censored array variable in the inspector. But i wrote the format for the other variables similar if not the same as it and yet they’re (Nil) instead of (size <number>)

the error comes from multiple lines like these ones, if i fix one by renaming, godot will point me to the next until i resolve all of it

var event = text.event_arrays[values.enc_events]
chosen = text.cas_dict[randi_range(0,2)]
chosen = text.flr_dict[randi_range(0,2)]

these in of themselves aren’t the problem though it seems. It may have something to do with my dialogue script where i store all the dialogue. for some reason apart from one array variable, all of it are (Nil) Array

Nice, yes changing the variable names usually destroys the exported data. You can prevent Nil values by giving your exported variables types. Such as @export var event_array: Array = [ etc but the data itself may still be destroyed leaving a saved, valid, 0-length array.

Seems like you need to update your nvidia drivers too

1 Like

i see i’ll try that then thanks

yeah i kinda refused to update nvidia drivers too often since my first experience updating my driver, the game i played a couple years ago started frame dropping so hard. I stayed on 427.11 for 2 whole years before updating. Now it’s nvidia 572.47. I might regress versions again

oh and yeah i have a lot of those artifacts that’s being shown in the bug report xD

This worked! editing via property no longer breaks it! tysm!

I will say you may want to look into using a dialogue system or making one of your own that reads text files. It’s not great to be writing dialogue in-code as you’ve seen it’s easy to destroy data if you need to move things around like variable names and/or it’s hard to add more to the data, like if you wanted to add a “weather_req” to each dialogue for rainy days. I have a lot of experience making complex dialogue “domain specific languages” feel free to reach out if you need any advice

You picked a uniquely buggy version to upgrade to, If you don’t want to update often that’s okay (I don’t want to either) but I’d recommend jumping up at least one more verison haha

1 Like