Page 1 of 1

caninsert() ignores inventory size

Posted: Tue Jul 15, 2014 7:46 am
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

Re: caninsert() ignores inventory size

Posted: Wed Jul 16, 2014 4:52 am
by slpwnd
What entity is this exactly?

Re: caninsert() ignores inventory size

Posted: Wed Jul 16, 2014 9:22 am
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

Re: caninsert() ignores inventory size

Posted: Wed Jul 16, 2014 9:55 am
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).

Re: caninsert() ignores inventory size

Posted: Wed Jul 16, 2014 9:59 am
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.