Save game is error when increase more data

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

Hi
I’m have func save game it’s working but when I increase more data it’ll error because in file save don’t have new data.

at first I have only hightscore in save_data and when I add Gold to save_data it’ll error
it need to delete save file for run game

var savegame = File.new() 
var save_path = "user://savegame.save" 
var save_data = {
	"HIGHTSCORE": 0,
	"Gold": 0,

func save():	
	save_data["HIGHTSCORE"] = HIGHTSCORE 
	save_data["Gold"] = Gold
	savegame.open(save_path, File.WRITE) 
	savegame.store_var(save_data) 
	savegame.close() 

func read_savegame():
	if not savegame.file_exists(save_path):
		create_save()
	if savegame.file_exists(save_path):
		savegame.open(save_path, File.READ)
		save_data = savegame.get_var() 
		savegame.close() 
		Gold = save_data["Gold"]
		HIGHTSCORE = save_data["HIGHTSCORE"]

func create_save():
	savegame.open(save_path, File.WRITE)
	savegame.store_var(save_data)
	savegame.close()
:bust_in_silhouette: Reply From: Inces

I barely understood this…

it is normal, that updating saving system will corrupt your saves. If You still want to use old saves, You need to do :

if save_data.has("Gold"):
     Gold = save_data["Gold"]

OK thank so much. :heart:

Lazyworker | 2022-04-30 07:03