kongkim
(kongkim)
March 8, 2016, 3:52pm
5
Well there is “addItem” and that gives a new stack/item. Then there is “IncrementItemQuantity” which acts against an existing stack, I know this works much better as I used to directly set the stack size, which caused issues, this function properly adds, and removes (if you give it a -neg value like -3) however if you have two stacks of wood (100 each total of 200) and you wanted to say “IncrementItemQuantity -300” it would only take away one stack.
So you may need to make some helper functions and an int too store the “needs to consume amount”. one function checks the inventory or your desired item, adding up all the quantities. then you compare the total quantities against the ‘needs to consume’ you can then loop around the inventory again calling another function that 1st compares the stacks current itemQuantity against the “needs to consume” if the need is greater you can use a clamp function where the max is supplied by the item quantity, this clamped value then subtracks from the need to consume, and calls the IncrementItemQuantity using that clamped value * -1 (turns it into a neg) now that is how you’d consume the correct amount.
But I think you’re just saying “Can I remove 1-2 items at random” less logic, but same final method “IncrementItemQuantity”
Ok im home now and look at it. Was not the IncrementItemQuantity i tried :S
But have tried to set it up using the IncrementItemQuantity but can’t really find out how to get it all to work.
Way do it has to be difficult to remove an item when its so easy to add one