• News

• Industries

• Learning & Support

• Community

• Marketplace

# Min Of Int Array: How can I get two indexes if they share the same value?

If I have an Int array with 3 entries: 1, 1, 2, is there a way for me to grab both 0 and 1 indexes with this node: https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Integer/MinOfIntArray/index.html

Min of Int Array will return the first indexs with the lowest value, so it will return index 0 of value one.

One possible solution, while it might not be the best, is to throw your array you are grabbing the values from into a temporary array. Get the min of that array, remove that index value from the array (which will also cause the indexes of the temp array to resize), and then get the min value of the array again, if <= to previous min value you grabbed, grab/store it, repeat. if > then stop grabbing/removing and do what you want with the values you retrieved.

Of course doing it that way will mess up the indexes, which is probably what you are using to identify what integer value corresponds with a particular actor/item from another array. If that’s the case, you could make a new structure that has the original index/id/actorreference/whatever stored in the structure so you don’t lose the original index.

Anywho it’s tough explaining it without knowing what you’re trying to accomplish, but that’s a couple of general thoughts I have on what you may be trying to do.

Thanks for the answer. My Array will be organised (I’m manually entering the data) and it will be sequential, with no more than two entries sharing a value. Example like this: 0, 1, 1, 2, 3, 4, 4, 5. It always ascends, but I what I really want to know is when do two values repeat.

These Intergers are actually paired to text in a separate array. Is there a way of me combining the ints and text into the same array? I’ve seen these map arrays but I don’t really understand how they work.

Here’s something I thought of:

I’m not sure if it works, because I didn’t tested it.
Every variable is local.

I decided to take a go at it for you, here’s my own take where it’s actually altering the initial min values to be max+one after storing it (to mark the value as already marked and checked so it’ll never again return as the min, instead of removing it from the array.)

The example also uses a custom blueprint structure, that takes in two integers, one marked for the initial index, and the other for the value. I tested it ingame and all seems to work well, though honestly there’s probably a better way to do it. This one has the added value though of storing the original index and value into a structure that you can for example, do a foreach loop on and reference an actor array if that initial integer array was made at the same time from an actor array with corresponding indexes.

Of course, this is probably not the cleanest approach but hey-oh it works as an initial example. Feel free to use/edit/whatever from it!

Thanks for your help guys. I’d not really thought of using structs, but they seem relevent.