Hello, I normally don't like to ask, but I'm hoping someone can help me make sense of this as I'm new to Godot. I've been pouring over tutorials, documentation, and forums all day with no luck.
The gist of it:
I'm trying to work out a save feature that I can save a main dictionary containing sub dictionaries with a bunch of variables from user input in one scene, and then load each sub dictionary up in another scene as a clickable button. (Think like a character creator, and then when finished you could click the character you made to start the game from a list of your characters.)
The problem I'm having is that every entry time I save the data, it overwrites what was there before, meaning only ONE key:sub dictionary ever shows up.
I have tried to use seek_end()
as some other people have posted, but when I do that, it simply doesn't save it, and when you back out of the character creator after hitting the save button, nothing has changed.
Can anyone help me shine a light on what I'm missing? I'm pretty sure the problem lies somewhere in how it's being saved, and when I tried to error check the store_var()
method, I get "Null" back instead of OK.
This is my main Save Code (after organizing the dictionaries)
func save_entry(playerdata):
var save_file = File.new()
if save_file.file_exists("user://PlayerData.dat"):
save_file.open("user://PlayerData.dat",File.READ_WRITE)
else:
save_file.open("user://PlayerData.dat",File.WRITE)
save_file.seek_end()
print(playerdata) #Just to test and make sure the data is organized right
var err = save_file.store_var(playerdata)
if err == OK : print("Saved Successfully")
else: print(err) #This just gives me "Null"
save_file.close()
and then on my scene that contains the list, it's like this:
func load_to_list():
var fileob = File.new()
if fileob.file_exists(loadfile): #Loadfile is a var with the filepath
fileob.open(loadfile, File.READ)
var playerlistdata : Dictionary = fileob.get_var()
fileob.close()
var keylist = playerlistdata.keys()
print(listsize) #just to confirm only 1 shows up
for char in keylist:
var button_instance = newbutton.instance()
get_node("ScrollContainer/Char List Container").add_child(button_instance)
button_instance.text = char
button_instance.next_scene_path = myplayerinfo
else:
print("No data file found.")
func _ready():
load_to_list()
Any help is appreciated. Spent a huge amount of time spinning my wheels on this.