Infinite Inventory using Structure Display

I have a structure called “inventory” which can hold string variables. Here is the inventory the player has:

index count
apple 3
banana 0
orange 2
wheat 0
wood 0

This should display in-game as:

Notice how the oranges move up in the inventory, despite bananas being after it. Bananas, Wood, and Wheat isn’t shown because it has a value of 0. How could I replicate an infinite inventory such as this one, that can hold as many inventory child variables as possible?

The list should also update in real time if one of the values change, and if they are set to 0, they should disappear entirely.

If you set or access a variable that hasn’t bee defined, GDevelop creates it and sets the value.

So if you want to add 5 mangoes to the structure, you just need to set the variable inventory[“mango”] to 5. Or more generically, inventory[VariableString(fruitName)] if fruitName was a variable with the name of the fruit.

To get it updated on screen realtime, clear all the inventory items on the screen, and iterate over all the structure’s children, displaying only those that have an inventory value > 0…