inventory.remove needs count >0, proposed >=0
Posted: Thu May 19, 2016 6:27 am
I'm trying to move items from one inventory to another and I have a 3 liner to do so:
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:
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:
or something even easier:
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
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;}
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)
Code: Select all
fakePlayer.move_inventory_to(car)