[Solved] How do I populate random items from inventory into my player inventory slots?

I’ve 4 inventory slots in my game.
And about 25 different items that I crammed into my inventory using ‘Add items to inventory’ described here.

I wish to populate the first slot at random, then remove the item from inventory. And then populate another random item in the next slot.

Do you know a way this could be achieved?

I was curious about this, so I tried to do it. It might be easier to take the items from objects or an array but I was curious if I could get the list from the inventory. It was a little easier than expected. I didn’t want to create a bunch of items, so I just used the numbers 1 through 25 as items. I added them to the inventory and then copied the inventory into a structure with the save inventory in variable. It then creates an array based on the items with a quantity. It uses the array tools extension to shuffle the array. It then uses the first item in the array. It removes it from inventory, adds it to a slot. then removes it from the array. The rest of the events are used to display what’s left in the inventory. I add the button just as a way to test the process.

try me: Each time to click the button it removes 4 numbers.
https://gd.games/keith_13579/random-inventory

Source: (click the green [code] and then [download zip]
https://github.com/doug13579/Gdvelop-pick-random-items-from-inventory

variables

Events

1 Like

You are amazing @Keith_1357

As usual, you’ve provided a simple yet deep reply!

Thank you!

1 Like