I am making a Godot FPS game and I want to incorporate a saving and loading system akin to those you would find in a lot of classic shooters. So the data I would have to save would be the following:
-Player position, player rotations, acquired weapons, amount of ammo for each ammo type, health, etc.
-The health, position, etc for every enemy.
-What level the player is actually on (each level is a different scene).
-What pickups and items have been taken.
-What objectives have been completed.
-What objects (doors, cutscene players, etc) have been activated.
-Etc.
I have searched around at the different kinds of save systems. I believe that saving whole scenes is inefficient, but saving so many values seems like it would be a lot. Of course, I heard thats fine for things like JSON files, although I am worried about organization.
In the end, I have never done anything like this and I am kind of lost in which approach I should take. If anyone could provide any pointers, that would be very helpful.
Both ConfigFile and JSON can serialize a Vector3 to and from text, you do not have to worry about converting it yourself. Objects and Resources will need some help converting, so if you can stick to dictionaries and base data types you’re good.
Sorry, another question. Whenever I get the Vector3 back it is a String, and I am having trouble making it a Vector3 again. I tried the following to convert but it does not work:
str_to_var(JSON.parse_string(save_dict[“position”]))
JSON.parse_string takes a string and returns a value. I think there is more wrong with this sample as the variable names lead me to believe you are saving a file, but using parse_string
Here is the doc’s minimal example converting to and from a string named json_string
var data_to_send = ["a", "b", "c"]
var json_string = JSON.stringify(data_to_send)
# Save data
# ...
# Retrieve data
var json = JSON.new()
var error = json.parse(json_string)
if error == OK:
var data_received = json.data
I finally figured it out. The problem was that save_dict[“position”] is a dictionary, not a file, so I had to do some conversions to convert the three values stored in it to vector values. Thanks for all of your help!