+1 vote

So I followed Game Endeavor's tutorial on YouTube and managed to create a save file, but I have one problem: They didn't cover how to link the directory to the actual game. Example script:

extends Sprite

const SAVE_DIR = "user://saves/"

var path = SAVE_DIR + "playerInfo.dat"

func _on_Save_pressed():
    var defaultData = {
    "player" : {
        "name" : "Bob",
        "race" : "Human",
        "gender" : "Male",
        "hairC" : "Brown",
        "hairS" : "Combed"
        },
    "options" : {
        "master" : 50,
        "music" : 50,
        "sfx" : 50
        }
    }

    var dir = Directory.new()
    if !dir.dir_exists(SAVE_DIR):
        dir.make_dir_recursive(SAVE_DIR)

    var file = File.new()
    var error = file.open_encrypted_with_pass(path, File.WRITE, "$3GAM$E_/SAvE!1")
    if error == OK:
        file.store_var(defaultData)
        file.close()

What I want is for the data in defaultData to actually have an effect on the game. Help would be appreciated.

Godot version 3.3.2
in Engine by (292 points)

1 Answer

0 votes
func load():
var file = File.new()
if file.file_exists(save_path):
    file.open(save_path,File.READ)
    defaultData = file.get_var()
    file.close()

the order that you save is the order that you load

by (256 points)

That isn't what I asked. I asked how to implement the save/load function in the actual game. For instance, how does the save function detect the "health" of the player?

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.