0 votes

I'm new to saving and loading games. I struggled to follow the documentation for a bit before I found a video that seemed to to work fine.

The project saves and loads as intended in the editor, but not after exporting. I made sure to export the *json as a resource, but I probably failed to set up the save data correctly in the first place.

Can somebody help me find out what I'm doing wrong?

const SaveFile = "user://save_file.save"

var data = {}

func _ready():
    load_data()

func save_data():
    var file = File.new()
    file.open(SaveFile, file.WRITE)
    file.store_var(data)
    file.close()

func load_data():
    var file = File.new()

    if not file.file_exists(SaveFile):
        data = {
            "LevelNum" : 0,
            "SpawnList" : []
        }
        save_data()

    file.open(SaveFile, File.READ)
    data = file.get_var()
    file.close()

func reset_data():
    data = {
        "LevelNum" : 0,
        "SpawnList" : []
    }
    save_data()
Godot version 3.5
in Engine by (14 points)

1 Answer

+1 vote

Maybe you should export as *.save instead of *.json, since your save file extension is a ".save". And I believe that exporting files in the Resource Tab only works when the file is inside your res:// folder, but I'm not sure about that.

by (20 points)

Exporting it as .save didn't work, so I just changed the extension of user://save_file to .json, which did the trick. I didn't need to save it to my res:// folder, many thanks.

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.