inventory.remove needs count >0, proposed >=0

Bugs that are actually features.
Post Reply
vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

inventory.remove needs count >0, proposed >=0

Post by vzybilly »

I'm trying to move items from one inventory to another and I have a 3 liner to do so:

Code: Select all

for name,count in pairs(fakePlayer.get_inventory(invMain).get_contents()) do
  fakePlayer.remove_item({name=name, count=car.insert({name=name, count=count})})
end
it crashes because remove_item wants count > 0 but this makes the need for a local to be made for each item in the inventory to check to see if it's 0.
wasted memory and wasted lua CPU cycles when the method could just return if 0, and throw the error if < 0.
All that would really be needed is at the beginning of the method, add in the equivilant of:

Code: Select all

if(count == 0){return;}
it will error out if the car inventory is full and there's items in the fakePlayer inventory.

I'll be posting a feature request later on for a method in inventory to do this logic to make things easier for mods, here is my thought of the method call:

Code: Select all

fakePlayer.get_inventory(invMain).move_to(car or car.get_inventory)
or something even easier:

Code: Select all

fakePlayer.move_inventory_to(car)
Will code for Food. I also have 11+ mods!

Post Reply

Return to “Not a bug”