Attention | Topic was automatically imported from the old Question2Answer platform. | |
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 global_settings.gd _ready() part V
func _ready():
display_options_btn.select(1 if Save.game_data.fullscreen_on else 0)
GlobalSettings.toggle_fullscreen(Save.game_data.fullscreen_on)
master_volume_slider.value = Save.game_data.master_vol
music_volume_slider.value = Save.game_data.music_vol
V save.gd V
extends Node
const SAVEFILE = "user://SAVEFILE.save"
var game_data = {}
func _ready():
load_data()
func load_data():
var file = File.new()
if not file.file_exists(SAVEFILE):
game_data = {
"fullscreen_on": true,
"master_vol": 0,
"music_vol": 0,
}
save_data()
file.open(SAVEFILE, File.READ)
game_data = file.get_var()
file.close()
func save_data():
var file = File.new()
file.open(SAVEFILE, File.WRITE)
file.store_var(game_data)
file.close()
`
Could someone please help? I’m fairly new to this.
Edited to fix code formatting…
jgodfrey | 2023-02-13 04:19