If it's just a simple game, you can do a save system within one script, but not recommended. As the number objects you want to save increases and when you need to save infos that are not just simple attributes, a save system within one script can be quit inconcenient.
Anyway:
For saving game infos, we use json.
So, you can save your game infos into a dictionary, and then save the dictionary into a file. For example, you have a dictionary of attributes for a character, you simply save this dictionary into your file using json.
(Simply put, the idea is to put text inside a file, and when load, we change things according to what is inside the file)
(Godot provides functions like to_json()
and parse_json()
)
I don't think there's a way to save the entire script. Scripts are what contains the code to function the game, not a save file that contains game infos.
As the game gets more complex, you may want to know more about the save system and how to save more complicated infos. Yesterday I had answered a question on save system, it might help. See This.