TAN
(TAN_)
July 28, 2019, 9:09am
4
Juice-Tin:
if you want to be able to rearrange items or have them keep position when earlier items are removed then rhe way you are doing it is correct.
The array would most likely always be the max inventory size and items would only occupy slots that are needed.
Adding a new item should loop through the array to find the first available slot.
I would personally use pointers as its cleaner considering an empty slot is completely empty.
You just need to make sure you check if the element exists before attempting to access its struct members, which is most likely what caused the crash.
Ex:
if(items*){
// there is an item in this slot. Its safe to access
item*->cost;
}
if something is not nullptr, it is considered true for if statements
edit: saw your other post. Youd need to make the array an array of pointers to use them.
Sorry for the late reply.
Thanks for your comment. I tried your solution and things really seem to be doing fine. I am marking this as solved.
Thank you again very much.