About saving and loading

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fsgni

I am making a saving system, but I can save but not read, I don’t know where the problem is. Below is my code。

I made a scene where I used the button to directly reference the read function, and then everything became very strange, I couldn’t control my character

func save_game():
print(“save”)
var save_game = File.new()
save_game.open(“user://savegame.save”, File.WRITE)
var persistingNodes = get_tree().get_nodes_in_group(“Persists”)
for node in persistingNodes:
var node_data = node.save()
save_game.store_line(to_json(node_data))
save_game.close()

func load_game():
var save_game = File.new()
if not save_game.file_exists(“user://savegame.save”):
return

var persistingNodes = get_tree().get_nodes_in_group("Persists")
for node in persistingNodes:
	node.queue_free()

save_game.open("user://savegame.save", File.READ)
while not save_game.eof_reached():
	var current_line = parse_json(save_game.get_line())
	if current_line != null:
		print("load")
		var newNode = load(current_line["filename"]).instance()
		get_node(current_line["parent"]).add_child(newNode, true)
		for property in current_line.keys():
			if (property == "filename"
			or property == "parent"
			or property == "gold"):
				continue
			newNode.set(property, current_line[property])
save_game.close()

I want to make a shop system to buy characters, hope someone can help,