0 votes

Okay, so I tried to go with a tutorial on load and save function and once I wrote the code, it showed that there is expected end of statement (var).

var error : int ResourceSaver.save(savepath, savegame)

I couldn't make it work, unless I removed the " : " and " int "

in Engine by (16 points)

Does it work if you add an = between the variable and the ResourceSaver?

var error : int = ResourceSaver.save(save_path, save_game)

1 Answer

0 votes

If you just need to save a variable or a dictionary this works fine (using it in my projects)

Everything in the "save" dictionary will be saved to the file, call the load_data to load it.

var save = {}

func save_data():
    var file = File.new()
    file.open("user://save",file.WRITE_READ)
    file.store_var(save)
    file.close()

func load_data():
    var file = File.new()
    if not file.file_exists("user://save"):
        return false
    file.open("user://save",file.READ)
    save = file.get_var()
    file.close()

check if the vaiable exist

func _ready():
    if not save.has("item"):
        save.item = {"worlds":{},"count":0}

or just set true

save.level_finished = true
by (193 points)
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 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 webmaster@godotengine.org with your username.