Storing weapon parts info

Godot Version

4.7

Question

Hi guys,

I’m new to godot and was wondering what is a good way of storing and then loading a weapon in system which allows player to choose parts for their weapon. Like they choose handle then blade and other attachment.

I thought about saving it as dictionary with dictionaries inside.

var weapon = {

    "handle" = {
       
          "blade" = {}
          "handle extension" = {
                  "empty_slot" = {}
          }
    }
}

Then use names of these dictionaries tho load info from resources with the same name.

(I try to do this so attachment also can have an attachment.)

But this looks really awkward and i was wondering if there is some better way.

Can any one help?

I recommend using Resources. Take a look at this post in which I walk someone through something similar.

Thanks, but

Maybe i didn’t understend your answer.

However my problem isn’t about doing something like inventory. More like doing inventory with items that give you more inventory space, but when you clear one od those items, slots added by that exact object also are cleared.

Sorry if your answer already explains that.

Do you mean something like:

var choices = {
    “knifes” = {
        “bases” = [
            “base_wooden”,
            “base_iron”
        ],
        “attachments” = [
            “blade_wood”,
            “blade_steel”,
            “casing_aerodynamic”
        ]
    “swords” = {…}
}

And

var current_knife = [“base_wooden”, “blade_steel”, “casing_aerodynamic”]
var current_sword = [“base_leather_hilt”, “blade_valyrian”, “tempered_2x”]

Does that work?

Oh, ok. I see you have a different problem. I still think this might help.

Resources will be a big part of your system, but you’re asking for a huge system. You haven’t presented a significant portion of the work required to what you ask, so forum folk can only give very basic advice. Inventory systems are asked a lot here, maybe you can pull from other threads or tutorials.

Doing it with resources would still be optimal. A basic setup can be made with a single resource class that represents a part. It stores the part info (name, image etc), an array of references to other parts, and a limit of how many parts can be added. This allows for assembling “trees” of parts of any complexity.

Thanks to all of you guys. I think I now know how to do this.

I just didn’t thought about doing this like inventory with items that add additional slots and then storing it as a list of resources with saved parent instead of having wierd hierarchy so when item get destroyed its attachment can also be removed.

For anyone from future searching for answers:

Create slot based inventory with only one slot. Then create resources for parts with number and type off additional slots. At the end create script that creates new slots based on chosen part and saves part used to create that slot so when parenting part is changed its children part can be deleted.