Godot Version
4.4
Question
Why does my get_var function on a save file always return null? I’m genuinely confused as this wasn’t doing it before, but has randomly started and I cannot find any culprit
Here is how the save function works
func createNewSaveFile(index) : #index because we select the save file from a list
var saveData = {}
for playerChild in GameUtil.get_all_children(GameManager.partyMembersNode) :
if playerChild.has_method("OnSave") :
saveData = playerChild.OnSave(saveData) #stores mostly simple data into the dictionary, but does also store extended Resource objects. I had this working before
#save map name
saveData["party"] = GameManager.getParty() ##gets an array of nodes, I've tried disabling this, does not change anything, I know this is sloppy, I'm planning on changing it
saveData["map_name"] = SceneManager.currentSceneName
saveData["player_position"] = GameManager.player.global_position
var fileName = str("save_game_", index,".dat")
if(index < saveFileListNames.size()) :
fileName = saveFileListNames[index]
var file = FileAccess.open("user://saves/"+fileName, FileAccess.WRITE)
file.store_var(saveData,true)
file.close()
print("Game Saved")
Now the file.get_var returns null in my actual loading function, but I don’t think it’s the problem because even modifying the bottom of the above code to this will print the stored data as null.
var begin = file.get_position()
file.store_var(saveData,true)
file.seek(begin)
print(file.get_var(true))
file.close()
That was the only similar problem to mine that I could find online. I’ve checked in my loading function and it’s not loading the wrong file. (file_exists() returns true) When I try get_open_error() it returns 0, meaning it’s not having any errors. I’m genuinely stumped.
Things seemed to change when I added the line to store the party info and when I added code after the call to create the new save file to store the data from the Dialogic Plugin. As I mentioned about the code for storing party data, I’ve tried turning both of these off, but it doesn’t change anything. Here is the code where I actually call the function after the player has clicked on a file list item:
func _on_file_list_item_clicked(index, at_position, mouse_button_index):
createNewSaveFile(index-1)
Dialogic.Save.save(str(index-1))
Does anyone know what I’m missing? If you need more information let me know! I really want to get this thing working. Thank you!