So, I've found that if I use the following code, then I can store all of the variables I want EXCEPT a the Vector2 variable for "last_position".
var file = File.new()
var savePath = "user://save_file.save"
var last_position = Vector2(0,0)
var player_initial_map_position = Vector2(160, 160)
var player_facing_direction = "down"
var current_scene = "res://Source/Levels/LevelOne.tscn"
var arrow_count = 0
var bomb_count = 0
var gold = 0
var player_inventory_items: Array = [
null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null, null, null,
];
var collected_pickups = {}
var trading_seq = "String"
var traded_items = {}
func saveGame():
var dict = {
"arrow_count": arrow_count,
"bomb_count": bomb_count,
"player_inventory_items": player_inventory_items,
"collected_pickups": collected_pickups,
"trading_seq": trading_seq,
"traded_items": traded_items,
"health": health,
"gold": gold,
"current_scene": current_scene,
}
file.open(savePath, file.WRITE)
file.store_line(to_json(dict))
file.close()
func loadGame():
if file.file_exists(savePath):
file.open(savePath, file.READ)
var tmp_data = file.get_as_text()
file.close()
var dict = {}
dict = parse_json(tmp_data)
arrow_count = dict["arrow_count"]
bomb_count = dict["bomb_count"]
player_inventory_items = dict["player_inventory_items"]
collected_pickups = dict["collected_pickups"]
trading_seq = dict["trading_seq"]
traded_items = dict["traded_items"]
health = dict["health"]
gold = dict["gold"]
current_scene = dict["current_scene"]
I've tried adding
file.store_var(last_position)
but unfortunately it seems to cause errors with loading the dictionary.
Any help is appreciated!