[0.9.2] getitemcount in onentitydied when ghosts are active

This subforum contains all the issues which we already resolved.
Post Reply
drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

[0.9.2] getitemcount in onentitydied when ghosts are active

Post by drs9999 »

I have these lines of code in the onEntityDied-event:

Code: Select all

if (event.entity.type == "container") or (event.entity.type == "smart-container") then
		local wasteAmount = event.entity.getitemcount("toxic-waste")
		if wasteAmount > 0 then
			game.pollute(event.entity.position, wasteAmount * 10)
		end
end
It works fine and as intended as long as ghostbuildings are not researched. After that getitemcount will always return 0.

Any idea for a workaround or is it a bug?

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: getitemcount + ghostbuildings

Post by ficolas »

Not sure if it is a bug or not, it is weird, so I guess it is.
For a workarround you can store every container entity in a glob table with the onbuildentity event, land store its waste contents every tick, and if in a tick it is not valid, then pollute what it had in the previous tick.

kovarex
Factorio Staff
Factorio Staff
Posts: 8079
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: getitemcount + ghostbuildings

Post by kovarex »

Yes, this is a bug, as the item is transferred to ghost and it's contents are cleared before the event is called, we should fix this, so I'm moving this to bug reports.

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

Re: [0.9.2] getitemcount in onentitydied when ghosts are act

Post by slpwnd »

This is now fixed for the 0.9.3.

Post Reply

Return to “Resolved Problems and Bugs”