Page 1 of 1
[Rseding91] [0.16.16] can_insert returns true when should be false
Posted: Mon Jan 22, 2018 8:08 pm
by Yehn
Using code as follows:
Code: Select all
local gridinventory = armor.grid.take_all()
for gear, cnt in pairs(gridinventory) do
if player.can_insert({name=gear, count=cnt}) then
player.insert({name=gear, count=cnt})
else
--player.print("WARNING: Inventory full.")
player.surface.spill_item_stack(player.position,{name=gear, count=cnt})
end
end
can_insert() returns true even when the inventory is full, causing insert() to fail.
Speculatively, this may happen because of slots available in the quickbar or other specialized inventory slots.
Re: [0.16.16] can_insert returns true when should be false
Posted: Tue Jan 23, 2018 4:09 am
by Rseding91
Please post some example save file where it fails to work correctly.
can_insert returns true if *any part* of the given stack can be put into the inventory. It doesn't care if only 1 of the 15,000,000 iron plates you're asking about can fit it will still return true - which is why it returns the count actually inserted.
Re: [0.16.16] can_insert returns true when should be false
Posted: Tue Jan 23, 2018 6:48 pm
by Yehn
Rseding91 wrote:Please post some example save file where it fails to work correctly.
can_insert returns true if *any part* of the given stack can be put into the inventory. It doesn't care if only 1 of the 15,000,000 iron plates you're asking about can fit it will still return true - which is why it returns the count actually inserted.
Right... 0 inserts should have been possible (I completely filled my inventory), and it did this with several items (so even if there was a slot, the next item would have failed completely).
I didn't keep a save, but it was just a new map with cheatmode on. If you fill up your main inventory and try adding something that goes to main inventory by default with player.can_insert/player.insert, that should reproduce it
Re: [0.16.16] can_insert returns true when should be false
Posted: Tue Jan 23, 2018 7:02 pm
by Yehn
https://youtu.be/4DI40jhLKgI
Here's a video showing the issue, default vanilla map with no mods loaded and so forth.
Re: [Rseding91] [0.16.16] can_insert returns true when should be false
Posted: Tue Jan 23, 2018 8:14 pm
by Rseding91
Ah I see. It's now fixed for the next version of 0.16.
Re: [Rseding91] [0.16.16] can_insert returns true when should be false
Posted: Wed Jan 24, 2018 4:48 am
by Yehn
Rseding91 wrote:Ah I see. It's now fixed for the next version of 0.16.
Awesome, thanks!