How to add and compare element in custom resource array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hexelon

Hello, i have an array of custom resources called “Items”. And i have several “items”. I need a way to stack them depends of they type and add them to inventory. How can i compare they type and add them to this array using GDScript?

:bust_in_silhouette: Reply From: JCDescy

Would a dictionary of arrays help? Make the dictonary keys the names of the types and the values the arrays of items of the corresponding type.
To put this in pseudo-code:

items = {
     "Type 1" : [array1item1, array1item2, ...],
     "Type 2" : [array2item1, array2item2, ...],
     ... etc.
}