+1 vote

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 save
game = File.new()
savegame.open("user://savegame.save", File.WRITE)
var persistingNodes = get
tree().getnodesingroup("Persists")
for node in persistingNodes:
var node
data = node.save()
savegame.storeline(tojson(nodedata))
save_game.close()

func loadgame():
var save
game = 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,

Godot version 3.3
in Engine by (13 points)

Please log in or register to answer this question.

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.