[posila] deconstruction order on item request proxy event

This subforum contains all the issues which we already resolved.
Post Reply
ichVII
Long Handed Inserter
Long Handed Inserter
Posts: 98
Joined: Mon Feb 27, 2017 10:16 pm
Contact:

[posila] deconstruction order on item request proxy event

Post by ichVII »

Steps to reproduce:
1. Use entity.order_deconstruction(...) on an item request proxy
2. Have a function called on the event on_marked_for_deconstruction
3. Have that function order entity.destroy()
4. crash

Note, that at step 3 entity.valid still returns true. I am using a heavily modded game, which does not help you, which is why i dont include a save game.

If the function checks, that entity.name is not "item-request-proxy", it just works. I am convinced I nailed down the problem to that.

Also, if you drag a deconstruction planer over the area containing the item request proxy, there is no issue. So, even if you call entity.destroy() on_marked_for_deconstruction, the game works.

I created most of a small test mod. With this, the steps to reproduce become:

1. build an entity with item requests, eg a blueprint of a beacon or assembler with modules. It will get instantly placed.
2. change test to true.

I have not tested this yet, becouse its 5 am and i want to sleep.


Control:

Code: Select all

local function marked_for_decon(event)
  if settings.global["instant_bp_and_decon"].value then 
    local ent =event.entity
	if ent.valid then 
	  ent.destroy() 
	end
  end  
end

local function on_Tick(event)
  if settings.global["test"].value then
    global.irp.mark_for_deconstruction(global.irp.force)
  end
end

local function on_built(event)
  local ent=event.created_entity
  if settings.global["instant_bp_and_decon"].value and (ent.name == "entity-ghost") then
     ent.revive() 
   end
  if ent.name = "item-request-proxy" then 
    global.irp = ent 
  end
end


script.on_event(defines.events.on_marked_for_deconstruction,marked_for_decon)
script.on_event(defines.events.on_tick,on_Tick)
script.on_event(defines.events.on_built_entity,on_built)


Settings:

Code: Select all

data:extend({
    {
        type = "bool-setting",
        name = "instant_bp_and_decon",
        setting_type = "runtime-global",
        default_value = true
      },
     {
        type = "bool-setting",
        name = "test",
        setting_type = "runtime-global",
        default_value = false
    }    
})



Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [posila] deconstruction order on item request proxy event

Post by Honktown »

if ent.name == "item-request-proxy" then * (two equals)

Interestingly, I made a beacon with modules and copy-pasted it, and I can't even PASTE it without an error (entity wasn't valid - it has no name).

Theory: the ghost was revived, so it doesn't exist anymore, instant crash there. Added a valid check to second if.

Enabled test. Instant crash because global.irp was nil in on_tick. Changed that, added a nil check then valid check, else removal if invalid.

Think what happens is technically item_request proxy is never *built*, so you can't act on it in an on_built_entity event.

If I'm understanding correctly, you want to remove item requests when a ghost is auto-revived. If so, there's a much easier way to do it:

Code: Select all

local function on_built(event)
  local ent = event.created_entity
  local item_request = nil
  if settings.global["instant_bp_and_decon"].value and (ent.name == "entity-ghost") then
    _, _, item_request = ent.revive({return_item_request_proxy = true})
    if item_request then
       --game.players[1].print("items requested")
       item_request.destroy()
    end
   end
  --if ent.valid then game.players[1].print("built entity: " .. ent.name) end
end

script.on_event(defines.events.on_built_entity,on_built)
Further, I don't understand what one would expect to happen on marking the item-request-proxy for deconstruction, as bots are what do deconstructing. In addition, I only see "mark_for_deconstruction" in one or two old forum posts. Currently "order_deconstruction(force[, player])" is listed on the api page.

A note on the deconstruction planner, mine cannot grab the item_request_proxy (raw.txt shows it has no collision box, but doesn't have the undeconstructable flag). It only marks the entity behind it.

Edit: if I remove the request-proxy when ghost-reviving, I don't think there's a way to have them at all. What's the goal here?
I have mods! I guess!
Link

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [posila] deconstruction order on item request proxy event

Post by posila »

Thanks for the report.

Fixed for 0.18.0

order_deconstruction() will destroy the proxy immediatelly and invokes pre_ghost_deconstructed event to be consistent with using deconstruction planner to remove an item request proxy.

Post Reply

Return to “Resolved Problems and Bugs”