When using store_var it doesn't save the data at all
Godot FileAccess store_var problem
- Edited
store_var() writes binary data to the file. How are you viewing the file? A text editor won't work. You need to use an application or command that can display raw binary data.
Or you can test the file by using get_var() to read the data, and print() to display it.
- Best Answerset by belgian_street_lamp
store_var
stores the value encoded to bytes, so opening the file in a text editor won't show anything useful.
In the code screenshot you provided, you use save_data()
, but you only showed save_data2()
, so I can't verify if it's also correct. But if the saved_game_data
is a Dictionary
and the paths are correct, then everything should be fine.
Double check that and also check the size of the file (should be bigger than 0B).
LoipesMas save_data() is the same script as save_data2 so that's not the problem. The file has 84B, and I used a similar method in godot 3 and it was showing in a text editor... Anyway the thing is when I load the data back it returns null.
If you opened the file in the text editor and saved it (it might have done that automatically), it will get corrupted.
Try saving again and loading again, without opening it in the text editor.
belgian_street_lamp ok I cleaned up some code, and it turns out that now it works! Sorry I wasted your time...
- Edited
belgian_street_lamp Call file.get_error()
immediately after calling file.store_var()
to check for possible io errors. You can also call file.flush()
or close the file to force the completion of the write operation.