How to find the index inside an array which contains min value?
Hi, is there a way to find the index that has the min value inside an Int array?
I have built an inventory system much like Resident Evil 2 (remake). Where there is a grid of inventory slots which hold items. I would then use a reload key (InventoryCheck) to remove 1 from the quantity of the slot.
I then set up a For each loop with break that will scan through all the items inside the inventory. Then an enumeration of Ammo types checks if any of the items match the ammo of the currently equipped weapon.
For now, I have all the (Array Index) which match the currently equipped ammo condition being added to an array. I then was trying to find the Max Int inside the array and remove (-1) from that slots quantity amount... I then use that Int as the Slot Index to change plugged into the "get (a copy)". This way the ammo amount is only taken from the inventory slot with the specified index number. For example: Index 0 would take ammo from Slot 1, Index 1 would take from Slot 2 and so on... But this gives an unwanted result :'(
This was meant to find the last slot containing ammo inside the inventory and remove from that. But when I press the reload key (InventoryCheck) it takes 1 away from the first ammo bow, then takes away 1 from the second ammo box each time it is pressed after that.
So what I really need to do here is somehow take all of the for loop ArrayIndex found that match the Equppied ammo type and add them to an array. I then will have to set each Array Elements value to that of the Slots quantity (Ammo Amount). Then out of that array of index (Slot Index), I need to find which on of those has the min value.
So then when I press the Reload Key, I want it to scan the inventory and if It finds ammo boxes that match the currently equipped weapon. Out of those slots take away 1 from the slot index that has the lowest amount of ammo or in this case the Index number which contains the smallest value.
Any help with this would be great. I really don't know how it could be done myself. I hope this makes sense, sorry if it's a bit long winded. It was the best way I could think of explaining the problem.
asked Apr 24 '19 at 09:02 PM in Blueprint Scripting
There are nodes 'max of int array', 'min of int array'...
answered Apr 25 '19 at 05:00 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here