+1 vote

hi, im making save system for my game,i need to save instance objects variable, but this code save only last object variable:

func _save():
var save_game = File.new()
save_game.open("res://saves/save.json", File.WRITE)
var save_nodes = get_tree().get_nodes_in_group("saved")
for node in save_nodes:
    if node.filename.empty():
        print("persistent node '%s' is not an instanced scene, skipped" % node.name)
        if !node.has_method("_save"):
            print("persistent node '%s' is missing a save() function, skipped" % node.name)
    var node_data = node.call("_save")

how can i save every object variable?

Godot version 3.4
in Engine by (99 points)

1 Answer

0 votes

я изменил код на это, и его работа:

func _save():
    var save_nodes = get_tree().get_nodes_in_group("saved")
    var data = {
    for node in save_nodes:
        data[node.name] = node._save()

func _load():
    var save_nodes = get_tree().get_nodes_in_group("saved")
    var data = FS.load_data('res://saves/txt_save/'+str(FS.OPN_LVL_ID))
    for node in save_nodes:


func save_data(filename, data):
func load_data(filename):
    file.open(filename, file.READ)
    var data = file.get_var()
    return data
by (99 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.