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 savegame():
print("save")
var savegame = File.new()
savegame.open("user://savegame.save", File.WRITE)
var persistingNodes = gettree().getnodesingroup("Persists")
for node in persistingNodes:
var nodedata = node.save()
savegame.storeline(tojson(nodedata))
save_game.close()
func loadgame():
var savegame = File.new()
if not savegame.fileexists("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,