So there is something I noticed with AC and it seems to not handle stackable items more intuitively when adding or removing those items at the index you click on (Or at least I couldn't seem to find anything related to it).
For example, I have a stackable item "ItemA" which has a max stack of 5. I have a max stack of itemA in the first slot in the inventory and another full stack of itemA in the second slot in the inventory. I right click the second slot in the inventory and it uses and removes the item by 1 on the first slot instead. so the itemA in first slot now has 4 stacks when the second slot should have the stacks to 4 since I clicked on that one.
I know it sounds like a little thing but it seems like an odd behavior and I had to make my own custom Add item method to make it more intuitive. It tries to find the stackable item in the inventory and check if it has enough space and if it does then increment the count of that stack in the closest index otherwise add it normally.
Now the non stack type of items does have the ability to do things intuitively, for example the actionlist for Inventory > Add or Remove and using the Remove Method you can check the remove last selected box to get the desired behavior but if its a stackable item it will remove ALL of the stack and not give you the option to reduce the count by set amount.
So that's where I'm at, is there a built in method that handles stack items in that desired way?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Here is my custom Add Item method so it can handle stackable items. It seems to work so far but I still need to do more testing.
I think the main issue here is that, if I understood you correctly, your right click is simply running an actionlist with the add/remove action, and the actionlist doesn't "know" which instance the click came from. My approach would probably be to code this into my custom inventory script - a right click would select the clicked item, run clickedInstance.Use(), and then remove the selected instance. The actionlist then would only take care of the actual effects of using the item (adding health if the item is bandages, for example).
But it'd be cool if we had a "remove (currently selected)" action that removed only whatever was selected at the time. It wouldn't be useful in this specific situation, but I can see how it would be good to have.
@Rairun Hello again, thanks for your help with the custom inventory script before.
As for your advice, I have already tried that when I was trying to figure out why the checking for item category actionlist wasn't working with the custom inventory script.
Here is a small snippet when right clicking to use item with my custom inventory script
Just so I can clarify the title for this for my desired behavior.
Adding stackable item to your inventory should first check if there is already existing item and if it has space then it should just increment that slot's stack count. That is what my custom Adding item method above does.
And removing stackable items when you use them by right clicking (which is done by my custom inventory script), it should use the inventory slot's item that you clicked on if you have multiple same stackable items but in different slots.
Regarding the original issue: how are you getting the behaviour of the wrong stack being updated when clicking? Is this from AC's built-in behaviour, a custom Action via the Item's "Standard interactions", or a hook into the OnMenuElementClick event?
If it's AC's behaviour with no custom scripting, please share shots of your Managers so that I can recreate the behaviour.
If it's via an event hook, OnMenuElementClick supplies the slot that was clicked on. This can be used to identify the corresponding ItemInstance with:
@ChrisIceBox I am using a custom inventory script that handles the controls. So let me first show you my custom inventory.
At the end of the code, you can see that right clicking an item calls the use method
clickedInstance.Use(0);
And then this is the actionlist it calls and runs. These are not custom actionlist. It's built in ones.
If I checked the "Remove last-selected" box, it removes the item from the correct index that I right click on BUT it removes ALL of the items and does not give you an option to set an amount to reduce by.
@Shadowz, what I meant is that you could have something like this:
Obviously you might not want the same behaviour for every type of item, but then I think you can easily use conditionals to limit the item deletion to the ones you want.
@Rairun I appreciate it, that works and seems to solve my problem but like you said different type of items will require conditional statements and there might be few other test cases/scenarios where it will either be too reliant on the custom inventory script (which could make it easier to break other aspects, cause weird behaviors or would require some more code for additional stuff).
I would rather let "
clickedInstance.Use(0);
" handle things like removing (and other stuff) that can be easily done in the actionlist editor and it would be easier and more flexible to work with.I might use your way as a last resort if its doable and doesn't cause too much complications but I will only know this as I continue to work on my project and see if it suits my needs and desired behaviors further down the line. But thank you for that. I really appreciate it.
Yeah, I get you. Having a "reduce count by" box for "remove last selected?" would be useful for sure.
@ChrisIceBox Which Manager do you require? the Inventory one?
Also, I tried to recreate the problem using the default setup on AC on a new project and it seems like even if its Built in and not using custom inventory script, it still has the same problem.
Here is a quick demonstration, Started a new game setup wizard. And then I made sure that I checked the Items can be reordered in menus.
I created a new item to test out, put the Selection mode to Stack. Gave it a capacity of 5.
I then added a button in scene for testing purposes. It calls this method:
Then I click on the button 4 times to add 4 to my inventory. (This is the default AC inventory, doesn't use custom script)
If you then move the 4 stack items to the second slot in inventory
And then try to add the item again to the inventory you will notice that rather than applying that item into the slot 2 item since it already exists and has enough space to carry 1 more, it instead makes a new one in the first slot.
So this is just an example for the Adding stackable item problem. The similar issue happens with the removing of stack item. The difference is that since the control is to right click to use item in inventory, it requires a custom inventory script and then the
clickedInstance.Use(0);
handles the removing of item except if you have two slots of full stack of same item in the inventory, it will use the first slot it can find even if you click on a second slot that has the same item.Ex. Right clicking the item to use
Result:
Again, the clickedInstance.Use(0) calls the actionlist that uses AC's built in Remove method, but it doesn't allow you to set amount to remove if you have remove last selected checked.
Thank you for the details.
The example you give still uses custom scripting to add the item to the inventory, and that's where you need to be explicit in telling AC where exactly you want to add the item to.
Instead of calling the InvCollection script's Add function, you can instead use Insert along with the index you want to add the new item to:
When it comes to removing items, you don't need to handle this through AC Actions - you can also do this via the Delete function as @Rairun notes.
This is a good point, and I shall look into see if this can be modified.
@ChrisIceBox If I add the item by count 1 using the built in AC actionlist, it still has the same issue.
Thank you for that code, it does work if you have the count set as 1 but if you try anymore than that then it will break. I tried changing the count to 2 and when I tried to add the item while my stack was at 4/5, it added 1 to it making it 5/5 but the other one just disappeared and nowhere to be seen.
Where as I am kind of expecting it to behave like if it can find any space in any other slots then it can merge with it, or if it has some space but not enough for the amount you are adding then it should add whatever you can fit into the stack until it becomes full and then add the leftovers in a new slot.
I feel like the stack items need a couple layer of extra logic to work smartly, will we be able to see hopefully a better handling of it in future updates perhaps? It would also be nice to get access and some control for the LastClickedInstance in the built in actionlist.
In the meantime, I guess I will try to make a custom method and then turn it into actionlist too.
If you're not involving custom scripting, then the default click behaviour of InventoryBox elements will handle stacking. If you don't involve ActionLists, left-clicking a "Stack" item will take one, right-clicking will put one back.
There's a lot of variation in what expected behaviour will be, so AC's inventory system is designed to be flexible to cater for a wide range - but it does mean that custom scripting needs to make that behaviour clear.
The Insert function's third, optional, parameter dictates the behaviour when adding to a slot that is occupied. This function also returns the added item as a new InvInstance class - you can read this instance's Count property to determine how many were actually transferred. For example: