Allow inserting 0 items into an inventory
Posted: Sun Oct 27, 2024 4:53 pm
inventory.insert and inventory.remove should just do nothing when inserting or removing 0 items instead of crashing.
Consider these two lines of code:
They now have to become this instead:
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.
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 })
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
I would understand crashing with negative amount, but adding/removing 0 items is a completely legitimate operation that just does nothing.