Godot Version
4.7
Question
I am working on a feature that saves the items in the shop to a file when the player quits the game so that when they rejoin the game it will reload the same shop items. Currently, I am saving several unique resources (shopItemData) onto an array in a Dictionary that is saved into a file and retrieving that data.
My issue is trying to retrieve the data. I have ran into several errors when I try to apply the resource data onto my shopItemSlots (Control Node).
Saving Shop Data
func QuitGameFromShop():
# Save Current Room
SaveManager.SaveScene(ID)
# Let game know that the player wuit from shop and save shop data
SaveManager.saveData["quitFromShop"] = true
# Save current Shop Items into Save Data
for i in shopItemDataSave.size():
SaveManager.saveData["ShopItems"].append(shopItemDataSave[i])
#SaveManager.saveData["ShopItems"].append_array(shopItemDataSave)
# Save Data
SaveManager._save()
get_tree().quit()
Loading Shop Data
if SaveManager.saveData["quitFromShop"] == true:
SaveManager.saveData["quitFromShop"] = false
print("Restocking old items")
for i in SaveManager.saveData["ShopItems"]:
var test = i.get_instance_id()
var test2 = instance_from_id(test)
print("--------------------------")
print(i)
print(test)
print(test2)
LoadShopItem(i)
print("--------------------------")
Apply Reloaded Shop Data to ShopItemSlot
func LoadShopItem(saveItemData):
var item = shopItem.instantiate()
item.itemData = saveItemData
item_container.add_child(item)
item.InitializeStats()
shopItemDataSave.append(saveItemData)
I am running into the following errors depending on what I do; when I use either the âiâ or âtest2â variable, I get the following error:
Invalid assignment of property or key âitemDataâ with value of type âEncodedObjectAsIDâ on a base object of type âControl (shopItemSlot.gd)â.
When I use the âtestâ variable, I get the following error:
Invalid assignment of property or key âitemDataâ with value of type âintâ on a base object of type âControl (shopItemSlot.gd)â.
Iâm pretty new to using godot and dictionaries as a whole, so my main question is: How Do I retrieve the Resource Data so from a dictionary so that I can apply the data to the object?