I am trying to save an Array[Switch
] to a file using store_var()
and FileAccess. However, when loading it back it comes back as an untyped Array
.
## Saves switches to the file specified in SAVE_PATH
func save_switches() -> void:
var file := FileAccess.open(SAVE_PATH, FileAccess.WRITE)
file.store_var(switches)
file.close()
## Loads switches from the file specified in SAVE_PATH
func load_switches() -> void:
if (FileAccess.file_exists(SAVE_PATH)):
var file := FileAccess.open(SAVE_PATH, FileAccess.READ)
var encoded_array : Array = file.get_var()
for encoded_switch : EncodedObjectAsID in encoded_array:
switches.append(instance_from_id(encoded_switch.object_id))
file.close()
else: print("Unable to find switches file to load")