Godot Version
4.2.2
Question
Hi!
I’ve been working in godot for a few months now on a personal project, and I’ve recently started to use custom resources to contain possible data for things like Items and NPCs. For the NPCs I’ve got a generic CrewMember resource with arrays of possible names and stats etc. as well as a function which picks things at random and passes them back to a script as a dictionary. Perhaps this isn’t quite how resources are meant to be used, but I’ve already got save/loading working with dictionaries, so I wanted to stick with that.
Weird thing though. As I save the data to my crew dictionary, one of the entries of data gets overwritten (“stats”), not all of the entries in the dictionary, just this one that is a dictionary itself. Every time I roll a new character and save that data to the crew dictionary, the new “stats” overwrites all other characters stats.
Does this have something to do with Resources? Dictionaries? I have this working via a class with arrays of possible data, but switching it to a resource seems to have done something weird. Any insight would be appreciated, or I’ll have to switch back to my old, less-flexible method.
The Function for reference, and it’s printout:
func new_crew(num : int):
#Create new characters in the amount indicated
for i in num:
var crew_member_data = crew_resource.create_character()
crew_member_data["order"] = str(i)
var new_name = crew_member_data["name"]
_characters_SAVE[new_name] = crew_member_data
print(new_name)
print("resource ", crew_member_data) # This is correct!
for key in _characters_SAVE:
print("saved : ", _characters_SAVE[key]) # This is correct UNTIL a new character is added, and then it's only correct for the newest character.
McNameFace
resource { "name": "McNameFace", "pronouns": 2, "role": 1, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 0, "StatB": 1, "StatC": 0, "StatD": 0, "StatE": 0 }, "scores": { }, "order": "0" }
saved : { "name": "McNameFace", "pronouns": 2, "role": 1, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 0, "StatB": 1, "StatC": 0, "StatD": 0, "StatE": 0 }, "scores": { }, "order": "0" }
Dr. Name
resource { "name": "Dr. Name", "pronouns": 3, "role": 0, "icon": "res://Icons/buttonA.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "1" }
saved : { "name": "McNameFace", "pronouns": 2, "role": 1, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "0" }
saved : { "name": "Dr. Name", "pronouns": 3, "role": 0, "icon": "res://Icons/buttonA.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "1" }
Namesdottir
resource { "name": "Namesdottir", "pronouns": 1, "role": 8, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 0, "StatB": 1, "StatC": 0, "StatD": 0, "StatE": 0 }, "scores": { }, "order": "2" }
saved : { "name": "McNameFace", "pronouns": 2, "role": 1, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 0, "StatB": 1, "StatC": 0, "StatD": 0, "StatE": 0 }, "scores": { }, "order": "0" }
saved : { "name": "Dr. Name", "pronouns": 3, "role": 0, "icon": "res://Icons/buttonA.png", "stats": { "StatA": 0, "StatB": 1, "StatC": 0, "StatD": 0, "StatE": 0 }, "scores": { }, "order": "1" }
saved : { "name": "Namesdottir", "pronouns": 1, "role": 8, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 0, "StatB": 1, "StatC": 0, "StatD": 0, "StatE": 0 }, "scores": { }, "order": "2" }
Namey
resource { "name": "Namey", "pronouns": 1, "role": 7, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "3" }
saved : { "name": "McNameFace", "pronouns": 2, "role": 1, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "0" }
saved : { "name": "Dr. Name", "pronouns": 3, "role": 0, "icon": "res://Icons/buttonA.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "1" }
saved : { "name": "Namesdottir", "pronouns": 1, "role": 8, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "2" }
saved : { "name": "Namey", "pronouns": 1, "role": 7, "icon": "res://Icons/buttonB.png", "stats": { "StatA": 1, "StatB": 0, "StatC": 0, "StatD": 0, "StatE": 1 }, "scores": { }, "order": "3" }