This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi ! ~ I've some troubles figuring out why godot is actually doing this. Here's my code for saving :

 `var save_game =
    save_game.open_encrypted_with_pass(save_path, File.WRITE, "Trololo")
    var save_buttons = get_tree().get_nodes_in_group("Persist")
    for node in save_buttons:
        node_data[node.get_path()] =


with a var node_data = {}

Now, it saves without any troubles, besides that.. it;ll save like that :
Line 1 : [Path] + data
Line 2 : [Path] + data + [Path other node] + data

And it'll do that with every node, just repeating them every line and adding a new one.

Each node has a func save() returning their variables, looking like that :

    func save():
var d = {
"Var1": var1,
"Var2": var2
return d

Because of that, I don't really know how to load my variables and add them to each of the objects :/ Hope there is enough info

in Engine by (86 points)
edited by

2 Answers

0 votes
Best answer

I will simply tell you to take a look again in the docs:
Do note a couple things:
first, we are saving variables not a whole scene
second, you cant save complex stuff like vectors(that is why the posx and posy in the demo)
third and MOST IMPORTANT: you need something to craft the nodes back as we are saving properties...

besides, your problem is because you create a dictionary and saves the full dict every time instead of the new line only, you wanna save the output not the full dict(or save only the full dict)

by (1,205 points)
selected by
func save():
save_ress = {
    "Gold": gold,
    "Crystal": crystal,
    "Gold_tour": gold_tour,
    "Crystal_tour": crystal_tour

return save_ress

Here is what I store on my save, so my save contains


print is printing this exact lineenter image description here
Stats are randomly generated atm

So, the problem you have is, you saved a json string as a value... what you want to do is take the data and do something like this(for the way you save at lease):


since you saved a json as a value of a key

It doesn't seem to work, or I'm misstyping something there:, File.READ)
var button_data = parse_json(save_game.get_as_text())
var Gold = button_data["/root/World/BackInterface"]["Gold"]

It print the exact same thing :x

try parsing the json inside the button_data["/root/World/BackInterface"] as well, File.READ)
var button_data = parse_json(save_game.get_as_text())
var Gold = parse_json(button_data["/root/World/BackInterface"])

Still printing the same entire line. I really hope I'm not misstyping and that is actually something I just don't understand

0 votes

In your for loop you are constructing node_data by assigning to it for each node. It looks like you are also calling store_line for each node. I don't think you need to do both.

Try either pulling store_line out of the loop or just store directly without building up a data structure first.

by (868 points)

Thanks a lot for your answer, it helped me comprehend a bit better the uses of each of those lines :)

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.