I am developing a multiplayer game, the task is to create an inventory that will add items to a certain hotbar slot, so that in the future it can be selected and used. the problem is that when using Items.Add regardless of the selected slot, items are added in order.
Because Items is an array. Using Add always adds to the end of the array.
If you want to replace an item at a set index then you would for instance use
Items[2] = myNewItem;
to check for this you can use
if (Items.IsValidIndex(2)){
Items[2] = myNewItem;
}
This would set Items third element (all arrays start from 0). Just make sure that the index you are setting is a valid index or you will get an out of bounds exception and crash your project.
1 Like
This worked together with SetNum on beginplay, but there was a problem with reducing the array, I use Items.RemoveAt(Counter, 1, false), and when I throw away or use an item, then all the items that go further in the count are shifted back, what can I do about it?