I have two global scripts (added to project settings/autoload) that i use to manage comunication between nodes (Global) and tracking story progression (Story). Is it possible to instansiate these scripts so that i can save and load them using:
var packed_scene = load("res://Saves/SavedGame.tscn")
# Instance the scene
var level_instance = packed_scene.instantiate()
main2D.add_child(level_instance)
I currently have the entire game instansiated to a node call MainMap, which is what i save into the tscn file.
Thanks in advance!
EDIT: I realised this is probably not possible to do, I can however instantiate a local script and use the global scripts as a reference holder, which is what i will be going for!
If you have an autoloaded script, you can define define variables in that script and access them anywhere in your project. For example, if your autoloaded class is called Story and it has a variable called foo, you should be able to access it using:
Story.foo
anywhere in your project.
Your question and code imply saving progress on a game. Are you trying to save progress in a game? That would be different.
Ahh, then take a look at the docs for Saving Games and keep in mind that there is a special path user:// that needs to be used when writing persistent files. You’re on the right track with the dictionary. The tutorial shows you how to turn it into a JSON file and read it again in the future.