caninsert() ignores inventory size

This subforum contains all the issues which we already resolved.
Post Reply
Dark
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Wed May 07, 2014 12:45 pm
Contact:

caninsert() ignores inventory size

Post by Dark »

This is a minor issue.

entity.caninsert() returns true despite the fact that entity's inventory is zero sized.

Workaround code:

Code: Select all

  if entity.caninsert{name=item_name, count=count} then
    entity.insert{name=item_name, count=1}  -- the real test
    if entity.getinventory(defines.inventory.fuel).getitemcount(item_name) >= 1 then
      if count - 1 > 0 then
        entity.insert({name=item_name, count=count-1})
      end
    end
  end

slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: caninsert() ignores inventory size

Post by slpwnd »

What entity is this exactly?

Dark
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Wed May 07, 2014 12:45 pm
Contact:

Re: caninsert() ignores inventory size

Post by Dark »

It is a car, with zero in fuel and inventory storage.

Mod that automatically placed fuel in any player build entities conflicted with it.
definition

slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: caninsert() ignores inventory size

Post by slpwnd »

So the car and the character had dummy methods for caninsert (always returning true instead of checking the actual contents of their inventories). This will be fixed in the 0.10.4. Just a side note - caninsert will return true if anything can be inserted (so caninsert for 100000000 will succeed even if there is a single space).

Dark
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Wed May 07, 2014 12:45 pm
Contact:

Re: caninsert() ignores inventory size

Post by Dark »

Thanks. Still better than always true, a check for how much was actually inserted can be done manually.
BTW, can "insert" method return inserted amount? That would make things trivial.

Post Reply

Return to “Resolved Problems and Bugs”