Need help with array inside a resource

Godot Version

4.2.1 Stable

Question

I have a custom resource called “BuildingData” that defines a list of export variables to hold information about a building that the player can construct (name, description, etc.).

I have another custom resource called “ItemData” that contains similar information about various items.

In my BuildingData resource, I want to add an array of (ItemData, int) to show how many of each item it takes to build that building. For example: “Wood”, 20 or “Stone”, 15, etc.

Is there a way to put an export variable in the BuildingData script to define this array?

I tried this:

@export var constructionArray: Array(ItemData, int)

What’s the syntax for declaring this? Or is there a different/better way to do what I’m attempting?

You probably will need a dictionary, and since you want a custom displayer, maybe this can help you there:

Thanks, I’ll check that out

You could make a resource called Stack that contains an item id and amount. Then your construction array could be declared like this:

@export var construction_array: Array[Stack]

You can then use stack resources to represent items in inventory as well.

But using a dictionary is probably a simpler solution if you already have a working item/inventory system and don’t want to change that.