Allow inserting 0 items into an inventory

Things that we aren't going to implement
kajacx
Inserter
Inserter
Posts: 20
Joined: Sun Mar 10, 2019 11:08 am
Contact:

Allow inserting 0 items into an inventory

Post by kajacx »

inventory.insert and inventory.remove should just do nothing when inserting or removing 0 items instead of crashing.

Consider these two lines of code:

Code: Select all

desired_inventory.remove({ name = desired.name, quality = desired.quality, count = taken })
target_inventory.insert({ name = desired.name, quality = desired.quality, count = taken })
They now have to become this instead:

Code: Select all

if taken > 0 then
    desired_inventory.remove({ name = desired.name, quality = desired.quality, count = taken })
    target_inventory.insert({ name = desired.name, quality = desired.quality, count = taken })
end
This wouldn't be so bad if this was the only place where I take or remove items from inventories, but putting it around every take and remove is just ugly, and when I forget, the mod will just crash for the user for no reason.

I would understand crashing with negative amount, but adding/removing 0 items is a completely legitimate operation that just does nothing.
curiosity
Filter Inserter
Filter Inserter
Posts: 637
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Allow inserting 0 items into an inventory

Post by curiosity »

It will save you those expensive API calls.

But if you have a list of items to remove that you want to loop over, consider not putting zero-count elements into it. That way you don't need the condition.

And the justification "add this because I always forget to check the condition" just seems very... entitled.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15584
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Allow inserting 0 items into an inventory

Post by Rseding91 »

Sorry but this will not be happening. It would require re-writing and handling every place we parse item stacks from Lua into the game to optionally check that the stack has a valid count and if not, don't use it.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Won't implement”