0 votes

Hi there.
For some reason my game don't save when i export it.
in the console say this:

ERROR: File must be opened before use.
At: core/bind/core_bind.cpp:2245

The code for save:

extends Node


var BestScore = 0

var Save = {
    BS = null}

var saveFile = 1
var SDirectory  =  str("res://Saves/save", saveFile)    

onready var ExitPause = get_node("ExitPause")

func _ready():
    if load_data():
        thingsToLoad()  


func save_data():
    var file = File.new()
    file.open(SDirectory,file.WRITE_READ)
    thingsToSave()
    file.store_var(Save)
    file.close()

# and load
func load_data():
    var file = File.new()
    if not file.file_exists(SDirectory):
        return false
    file.open(SDirectory,file.READ)
    Save = file.get_var()
    file.close()
    return true

func thingsToSave():
    Save = {
        BS = BestScore
        }

func thingsToLoad():
    BestScore = Save.BS

Player function that saves:

func dead():
    Gv.save_data()
    var _RC = get_tree().reload_current_scene()
Godot version 3.2.3
in Engine by (73 points)

1 Answer

+1 vote

You need to use user:// instead of res://

You can read here why.

by (1,448 points)

Still doesn't work :(

Is it the same error?

yes, but know it not even give me the error

You have to give us more information...

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.