How can I swap multiple items in my inventory using "Swap array"?

I want to check all the indexes in my inventory and change them if (for example) they are not food. I want to place them in the first slots in an organized and pretty way.

The way I’m doing it: For each loop > Check if its not an empty index at - 1 at current index and if its not food. Then, swap.

But sometimes my canned beans stop in the middle of the slots. They stay there instead of coming up. :rofl:

That won’t work, it will only move everything along by 1.

You could foreach through the array, and put it all in a new array, and the copy back

( example with ints )

Well, I was thinking about this right now. It won’t work, it only changes 1, that’s why the slots don’t go up. And in this case of copying the array it also wouldn’t work because if I consumed 1 item how would I have the correct quantities, weight, etc. Although… I could compare them… I’m thinking about that as I write. :thinking: :rofl:

1 Like