Help with getting info from an Array

Hey Everyone

Let’s say I have an array with 10 items in it and 5 of those items are the same (basically an Inventory with 10 slots and there are atleast 5 identical items which aren’t stackable so they take a slot each in there).

Is there anyway I could pull from the inventory say the first 3 of those identical items along with their index so I can basically delete them? How would I go about doing this?

Thanks.

if you want to make the array unique, start with a reverse loop from last to 2nd item, lets say that gives you item A. inside it, run a second loop from “current index - 1” to 0, that gives you item B. ib B=A, remove index of A.
this would only remove the duplicate items, keeping one intact, meaning #(1,2,2,3,3,2,1) will become #(1,2,3)

Interesting, but not really what i’m after I don’t think. Basically think of it like this. I have an inventory with 5 slots all full of items, 4 of those are Sticks and 1 is Cloth (so Array would be “SCSSS”. I want to craft a bat and for that I need 3 sticks.

How would I go about getting the indexes of the first 3 sticks and storing them so I can then remove them from the inventory when I press ‘Create Bat’?

So first I would do a check to ensure I have enough Sticks in my inventory (this i’ve done), but I don’t know how to store the indexes of the first 3 sticks I come across when doing a loop in my inventory and then deleting them at the press of a button. I’m not even sure this is the best way to go about it.

I’m sorry if i’m not explaining it properly. Still not used to everything yet and arrays are my worst enemy at the moment :slight_smile:

Actually never mind. I think I have it now. I basically did a for each loop with break, and once I found three sticks, I made an array with just those indexes and basically used that to then delete the items from the inventory array at those indexes.

I really hate arrays :slight_smile:

you could just perform find item - remove three times = that would find the first stick, remove it, then repeat
with your solution, be careful to remove in descending order, starting with the last index

I tried to use Array Find but since my array is a struct it never finds the item which is why I had to resort to a Loop instead.

May I ask why remove in descending order? Is it because if I remove from ascending order, everything else would shift forward so I would then be deleting the wrong things after the first one?

I’ll have to do more testing to iron out the issues.

exactly. take array #(A, B, C, D, E); say you want to remove A and E, so index 1 and 5. if you remove index 1 first, E becomes index 5, and will not be found. hence you reverse loop and remove 5, then 1