Page 1 of 1

[0.12.6][po]LuaInventory.insert into trash doesn't call bots

Posted: Wed Sep 09, 2015 11:00 am
by Choumiko
When inserting items into the trash inventory via script, these items don't get picked up by logistics bots.
It works if those items got inserted when the player was outside of logistics range at the time of insertion or if he walks out of range after insertion and then walks back in.

Code: Select all

function on_tick(event)
  if event.tick % 120 == 0 then
    for pi, player in pairs(game.players) do
      if not player.valid or not player.connected or not global.config[player.name] then
        break
      end
      for i, item in pairs(global.config[player.name]) do
        if item.name == "" then
          break
        end
        local stack = {name=item.name, count=1}
        local count = player.get_item_count(item.name)
        local desired = item.count
        local diff = count - desired
        if diff > 0 then
          player.print(item.name.. ": " .. diff)
          local trash = player.get_inventory(defines.inventory.player_trash)
          for j=1,diff do
            if trash.can_insert(stack) then
              player.remove_item(stack)
              trash.insert(stack)
            end
          end
        end
      end
    end
  end
end
global.config[player.name] is a table of items that should get moved to trash by the mod

Re: [0.12.6][po]LuaInventory.insert into trash doesn't call bots

Posted: Wed Sep 09, 2015 1:36 pm
by posila
Thanks for the report, fixed for next release.