Reputation: 1
I have an inventory array that I want to find the first empty slot in the said array and put the Resource the player picks up into that slot. I'm a little familiar already with C programming and am pretty sure that a for loop would work nicely, I just can't seem to get it to work for me.
Upvotes: 0
Views: 1453
Reputation: 2690
You can use Array.find to find the index of first element of your array that is null
(assuming you're using null
to indicate empty inventory slots).
It will return the index of the first empty slot, in which case you'd do inventory_array[index] = picked_up_item
. Or, if the inventory is full (i.e. there is no null
element), it will return -1, in which case you should do something reasonable (like not pick the item up).
Upvotes: 1