It would help a lot if you could create a autoload script so you can save or load your data anywhere in the game. Like a Global.gd
From there you need a dictionary to store your data. For example, a dictionary named save_data:
var save_data = {
"score": 0,
"name": "NAME"
}
Then you need to create a file(by code) to store the data structure: "save_data"
func save():
var cfgFile = File.new()
cfgFile.open("user://save.cfg", File.WRITE)
cfgFile.store_line(to_json(save_data))
cfgFile.close()
You call this function everytime you need to save data. It stores "save_data" into a file named "save.cfg", the "user" location can be found if you go to [Project>Open Project Data Folder]
Then in order to load this data:
func load():
var cfgFile = File.new()
if not cfgFile.fileExists("user://save.cfg", File.READ)
save()
return
cfgFile.open("user://save.cfg", File.READ)
var data = parse_json(cfgFile.get_as_text())
save_data.score = data.score
save_data.name = data.name
First you check if the file exists, if not, then you call save() so the file can be created.
Then the file is opened and passed into a variable named data.
You then retrieve this data back into your save_data dictionary.
So how do you exactly use these functions to save data?
In your main game logic(script/gd)where you need to save the score, If you created an autoload Global.gd, basically you just call :
Global.save_data.score = your_player_score
Global.save_data.name = "SOME PLAYER NAME"
Global.save()
And retrieving the data is also simple:
Global.load()
score = Global.save_data.score
name = Global.save_data.name
Disclaimer: In no way I'm saying this is the only way to handle saving data. While this works, it's also a good way of introducing how to handle loading and writing into file.
The next step is learning groups and organizing your scene tree.
You can find groups on the [Node] Tab next to the [Inspector] tab.
Under [Node] Tab, there is \Signals\ , and right next to it is \Groups\
Then on your scene tree, select any node you wish to save. Once it is highlighted, go back to the \Groups\ and type a name in the textbox, and hit [Add]. You'll notice your selected node has a new ICON and below the Manage Groups a new entry. It means your selected node is now in that group.
Once you have cross this bridge, go back to the documentation and learn more about saving.