0 votes

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 savedata and when I add Gold to savedata 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()
in Engine by (26 points)
edited by

1 Answer

+1 vote
Best answer

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"]
by (7,925 points)
selected by

OK thank so much. ♥

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.