0 votes

(Sorry for my English, I use Google translator)
Created a save system, the file is saved normally, but I can't load it, how can I do it?
Global variable:

func save():
var file = File.new()
if file.open("user://saved_game.txt", File.WRITE) != 0:
    print("Error opening file")
return
file.store_string(player.txt)
file.close()

func load():
   var file = File.new()
   if not file.file_exists("user://saved_game.txt"):
       print("No file saved!")
       return
   if file.open("user://saved_game.txt", File.READ) != 0:
       print("Error opening file")
       return

Another script:

onready var p = Global.player

func _ready():
    $Button.connect('pressed', self, 'saving')
    $Button2.connect('pressed', self, 'loading')

func saving():
    p.name = $LineEdit.text
    Global.save()
    print('saved')

func loading():
    Global.load()
    $Label.text = p.name
in Engine by (61 points)

1 Answer

0 votes

You shouldn't create a new file in the load func. See this tutorial for more infos: https://m.youtube.com/watch?v=EteQMVK2joI

by (232 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 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.