I create an object through my_object.new()
and then add it to an array. This array is then saved to a savefile to then be loaded. When I load the savefile, the object turns up as null in the array. Is this something I'm doing wrong? Thx in advanced
Save/load functions:
unc saveGame():
print(str(party))
var savedScene = get_tree().current_scene.filename
var savedPos = get_tree().get_nodes_in_group("Player")[0].position
var data = {
"party": party,
"inventory": inventory,
"equipment": equipment,
"keyItems": keyItems,
"gold": gold,
#"questList": AllQuests.questArray,
"currentQuests": currentQuests,
"completedQuests": completedQuests,
"currentScene": savedScene,
"currentPos": savedPos,
}
var file = File.new()
file.open(savePath,File.WRITE)
file.close()
var error = file.open(savePath,File.WRITE)
if error == OK:
file.store_var(data)
file.close()
print("Saved")
func loadGame():
var loadedData
var file = File.new()
if file.file_exists(savePath):
var error = file.open(savePath,File.READ)
if error == OK:
loadedData = file.get_var()
print(str(loadedData))
yield(get_tree().create_timer(1),"timeout")
file.close()
parseData(loadedData)
SceneChanger.changeScene(loadedData.currentScene,0)
print("loaded")
parseData(loadedData)
func parseData(data):
clearData()
for id in data.party:
party.append(instance_from_id(id.object_id))
print(str(instance_from_id(id.object_id)))
for id in data.inventory:
inventory.append(instance_from_id(id.object_id))
for id in data.equipment:
equipment.append(instance_from_id(id.object_id))
for id in data.keyItems:
keyItems.append(instance_from_id(id.object_id))
gold = data.gold
for id in data.currentQuests:
currentQuests.append(instance_from_id(id.object_id))
for id in data.completedQuests:
completedQuests.append(instance_from_id(id.object_id))
previousPos = data.currentPos