![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Comet |
(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