How do I fix the 'Invalid get index' error?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By redteller

I’ve got a saving system for my settings working and tried to add get other stuff to save but they didn’t work although the game would still run with no errors. After adding Save.load_data() to my _ready() func where the the variables are on the global script, I’ve starting getting the error;
"Invalid get index 'fullscreen_on' (on base: 'Dictionary')."
This error shows up in my global settings script in the first line of the _ready() func.

V _ready() part V

func _ready(): if Save.game_data.fullscreen_on else 0)
	master_volume_slider.value = Save.game_data.master_vol
	music_volume_slider.value = Save.game_data.music_vol 


extends Node

const SAVEFILE = "user://"

var game_data = {}

func _ready():

func load_data():
	var file =
	if not file.file_exists(SAVEFILE):
		game_data = {
			"fullscreen_on": true,
			"master_vol": 0,
			"music_vol": 0,
		save_data(), File.READ)
	game_data = file.get_var()

func save_data():
	var file =, File.WRITE)

`here is the image of can't get formatting to work

Could someone please help? I’m fairly new to this.

Edited to fix code formatting…

jgodfrey | 2023-02-13 04:19

:bust_in_silhouette: Reply From: jgodfrey

So, the error is pretty straightforward. Your Dictionary simply doesn’t contain a key named fullscreen_on. You’ll need to figure out why that is…

Thanks for the reply but the key is in the dictionary but it doesn’t seem to register. I have included a screenshot of the dictionary.

redteller | 2023-02-13 02:31

I’m confident that the key is not in the dictionary at the time it’s being accessed. It could be a timing issue, or something in your save logic, or ??. If you put a break point on the line where you’re getting the error and inspect the dictionary, I assume you’ll see that it does not contain the key in question…

jgodfrey | 2023-02-13 04:17