0 votes

hi , im making 2d level editor ,i got an error when i making load,
invalid get index 'spike' on base(Dictionary)
code:

func _save():
    var save_nodes = get_tree().get_nodes_in_group("saved")
    var data = {
        "object" : {}
        }
    for node in save_nodes:
        data["object"][node.name] = node._save()
    FS.save_data(get_parent().level_id,data)
    print(data)
func _load():
    var save_nodes = get_tree().get_nodes_in_group("saved")
    var data = FS.load_data('save')
    for node in save_nodes:
        node._load(data["object"][node.name])

global code:

func save_data(filename, data):
    file.open('res://saves/txt_save/'+filename,file.WRITE)
    file.store_var(data)
    file.close()
func load_data(filename):
    file.open('res://saves/txt_save/'+filename, file.READ)
    var data = file.get_var()
    file.close()
    return data

someone can help me

Godot version 3.4
in Engine by (99 points)

1 Answer

0 votes

i changed code to this, and its work:

func _save():
    var save_nodes = get_tree().get_nodes_in_group("saved")
    var data = {
        }
    for node in save_nodes:
        data[node.name] = node._save()
    FS.save_data('res://saves/txt_save/'+str(FS.OPN_LVL_ID),data)
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:
        node._load(data[node.name])

global

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