[0.17.72] Cleaning the inventory does not work

Bugs that are actually features.
Post Reply
XaLpHa89
Fast Inserter
Fast Inserter
Posts: 119
Joined: Wed Jan 24, 2018 6:59 am
Contact:

[0.17.72] Cleaning the inventory does not work

Post by XaLpHa89 »

I created a character and ordered him to mine ore. What works so far, the ore accumulation is now great, is still filed only an ore and emptied the inventory. Now the problem, the number in the inventory increases for no apparent reason.

Code: Select all

        if game.tick % 60 == 0 and npc_worker ~= nil then

            local inventory = npc_worker.get_main_inventory()

            local item_count = inventory.get_item_count( 'iron-ore' )

            game.surfaces.nauvis.create_entity( { name = 'flying-text', position = { 4, 4 }, text = item_count .. ' [img=item/iron-ore]', color = { r = 0.98, g = 0.66, b = 0.22 } } )

            if item_count > 0 then

                game.surfaces.nauvis.spill_item_stack( { 6, 6 }, { name = 'iron-ore', count = item_count }, true )

                inventory.clear()

            end

        end
20191020062105_1.jpg
20191020062105_1.jpg (281.45 KiB) Viewed 1517 times

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [0.17.72] Cleaning the inventory does not work

Post by boskid »

Cannot reproduce.

Code: Select all

/c
    global.npc_worker = game.surfaces[1].create_entity{name="character", position={0,0}, force="player"}
    global.npc_worker.selected = game.surfaces[1].create_entity{name="iron-ore", position={0.5, 0.5}, amount=10000}
    global.npc_worker.mining_state = {mining=true, position={0.5, 0.5}}
    script.on_nth_tick(60, function(e)
        if global.npc_worker and global.npc_worker.valid then
            local inventory = global.npc_worker.get_main_inventory()
            local item_count = inventory.get_item_count( 'iron-ore' )
            game.surfaces.nauvis.create_entity( { name = 'flying-text', position = { 4, 4 }, text = item_count .. ' [img=item/iron-ore]', color = { r = 0.98, g = 0.66, b = 0.22 } } )
            if item_count > 0 then
                game.surfaces.nauvis.spill_item_stack( { 6, 6 }, { name = 'iron-ore', count = item_count }, true )
                inventory.clear()
            end
        end
    end)
77008-failed-reproduction.gif
77008-failed-reproduction.gif (541.2 KiB) Viewed 1466 times

gallomimia
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Fri Apr 22, 2016 6:20 pm
Contact:

Re: [0.17.72] Cleaning the inventory does not work

Post by gallomimia »

......
WHAT?

XaLpHa89
Fast Inserter
Fast Inserter
Posts: 119
Joined: Wed Jan 24, 2018 6:59 am
Contact:

Re: [0.17.72] Cleaning the inventory does not work

Post by XaLpHa89 »

It is the position. The degradable ore collides with the ore lying on the ground. I just do not understand, the value in the inventory increases and still only one ore is deposited on the ground.
20191021053701_1.jpg
20191021053701_1.jpg (644.03 KiB) Viewed 1417 times

XaLpHa89
Fast Inserter
Fast Inserter
Posts: 119
Joined: Wed Jan 24, 2018 6:59 am
Contact:

Re: [0.17.72] Cleaning the inventory does not work

Post by XaLpHa89 »

After setting the value of "enable_looted" to false in function "spill_item_stack", everything works. So the NPC fills itself again and again?

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [0.17.72] Cleaning the inventory does not work

Post by boskid »

https://lua-api.factorio.com/latest/LuaSurface.html#LuaSurface.spill_item_stack wrote:enable_looted :: boolean (optional): When true, each created item will be flagged with the LuaEntity::to_be_looted flag.
https://lua-api.factorio.com/latest/LuaEntity.html#LuaEntity.to_be_looted wrote:to_be_looted :: boolean [Read-Write]
Will this entity be picked up automatically when the player walks over it?

Post Reply

Return to “Not a bug”