[Rseding91] [0.16.16] can_insert returns true when should be false

This subforum contains all the issues which we already resolved.
Post Reply
Yehn
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Tue Jul 12, 2016 3:45 am
Contact:

[Rseding91] [0.16.16] can_insert returns true when should be false

Post by Yehn » Mon Jan 22, 2018 8:08 pm

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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 9453
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.16.16] can_insert returns true when should be false

Post by Rseding91 » Tue Jan 23, 2018 4:09 am

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.
If you want to get ahold of me I'm almost always on Discord.

Yehn
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Re: [0.16.16] can_insert returns true when should be false

Post by Yehn » Tue Jan 23, 2018 6:48 pm

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

Yehn
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Re: [0.16.16] can_insert returns true when should be false

Post by Yehn » Tue Jan 23, 2018 7:02 pm

https://youtu.be/4DI40jhLKgI

Here's a video showing the issue, default vanilla map with no mods loaded and so forth.

Rseding91
Factorio Staff
Factorio Staff
Posts: 9453
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [Rseding91] [0.16.16] can_insert returns true when should be false

Post by Rseding91 » Tue Jan 23, 2018 8:14 pm

Ah I see. It's now fixed for the next version of 0.16.
If you want to get ahold of me I'm almost always on Discord.

Yehn
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Tue Jul 12, 2016 3:45 am
Contact:

Re: [Rseding91] [0.16.16] can_insert returns true when should be false

Post by Yehn » Wed Jan 24, 2018 4:48 am

Rseding91 wrote:Ah I see. It's now fixed for the next version of 0.16.
Awesome, thanks!

Post Reply

Return to “Resolved Problems and Bugs”

Who is online

Users browsing this forum: No registered users