how to get the index of two identical items in array?

I doing a equipment system, i have this widget that contains my slots

When I put an item in one of the slots, the item is added to my equipment item array

now I’m trying to get the index of the item that is in the slot

here I am getting the item index, the problem is: if I have 2 identical items in 2 different slots, I will receive the same index for both

This is happening considering that I’m looking for items with the same id, but that’s not what I’m looking for, I want to get the index of each item even though they are the same, how should I do?

The search result should be an array of int that you fill if the items match.

I’ll assume that the search is currently in a function, and you call Return Node after the first match - now you only need to do this at the end of the slot array. You need to make a local array variable and return that.

I didn’t understand very well, I tried this way and it didn’t work

You should exit the function (call Return Node) at the end of the loop.
And add a name check before adding a value to the array, of course.

And now your function should return an array instead of a single value.

i did this in my function

and this in my widget


)

but still not working

Where is the check for name matches?

Here you need to display the message not at the end (completed), but at each stage of the loop (loop body).

Here’s how I’m doing it, I want as soon as the item is added to my equipment array, it takes the index of that item and passes it to my slot, would the id check really be necessary in this case?

2024-11-01 12-07-50.mkv (25.3 MB)

something that I don’t know if it influences: my equipment UI is just an overlay with several slot UIs

This way it worked, I can get the index of the slot that is included in the equipment array

When I pull the item out of the equipment slot, I want to remove it from the equipment array, I’m doing it this way:

Now is there just a problem:

each slot has a fixed index, whenever I remove the item from the array, the item that was index 1 will become index 0, but in my slot it will still be index 1, how can I update the index whenever you remove an item?

For each, if index item == desired item, print index

Should I do this when removing the item from slot?

If your tryin to remove an item without affecting other items index, you’d want to remove array item instead of remove index

Hi,
for a fixed inventory.an easier way is that not to add items to the array.you could pre-define the array length.
and give every widget slots an index manually.
when dropping on the slot,you can get the index in the slot and use that index to modify the array in player.
same for removing,just set an array member to empty using index from widget slot.

I did this, now this is what happens: I programmed it so that if the slot is empty, I can’t drag it, if I don’t put any item it works, but if I put an item, remove that item, I can drag the slot even without content inside

here the blueprint

here the problem
2024-11-01 17-40-33.mkv (16.9 MB)

I’m not sure if that’s the problem in this case, but using Text as an ID is not the best idea. If I remember correctly (from personal experiments), in PIE the comparison is done character by character, but when running Standalone (and in a packed project) the comparison is done by TextID (if localization of this text is enabled, as in your case). And the problem (feature) is that it is unique for each text. Therefore, when comparing you will get “false” in almost all cases, even for two visually identical texts.

this is the debug time.you can print it out to see if the the text is empty.

if it’s not empty means that the issue might be in the removing process.

If it’s empty means the engine has problems comparing text like @PREDALIEN mentioned.(I’m not sure this too)
so you can compare something else like string,name,integer,etc.

for some reason, whenever I placed an item in the slot, even after removing it, it always returned that the slot was no longer empty, the solution I found was to create a function in the component to check if the slot had something based on the index

So i put the function in a branch, and now it’s working, which is curious, considering it’s the same logic

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.