[Solved] Plz help with "Entity is not a corpse." error on entity with name "character-corpse"

Place to get help with not working mods / modding interface.
User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 884
Joined: Sun Mar 20, 2016 2:51 am
Contact:

[Solved] Plz help with "Entity is not a corpse." error on entity with name "character-corpse"

Post by Impatient »

Summary
A search with "find_entities_filtered" finds one result, which's name property is "character-corpse", but when I try to access it's "corpse_expires" property, the exception "Entity is not a corpse." is thrown. What am I doing wrong?
Details
I am trying to access the "corpse_expires" ( https://lua-api.factorio.com/latest/Lua ... se_expires ) property of a LuaEntity that should be a "character-corpse". This is the code I am running after the character of a player dies (event on_player_died):

Code: Select all

impaUtil.eventHandlers.on_player_died.makeCorpseNotExpire = function(eventData)
	log("Event '"..tostring(impaUtil.getEventName(eventData.name)).."' triggered (Player "..tostring(eventData.player_index)..")")
	log(impaUtil.getVarContentsText(eventData,"eventData"))
	local p = game.players[eventData.player_index].character.position
	--log(impaUtil.getVarContentsText(p,"player position"))
	local s = game.players[eventData.player_index].character.surface
	local result = s.find_entities_filtered{position = p, radius = 1, name = "character-corpse"}
	log(impaUtil.getVarContentsText(table_size(result),"table_size(result) find_entities_filtered"))
	for k,v in pairs(result) do
		log(impaUtil.getVarContentsText(tostring(k),"tostring(k)"))
		log(impaUtil.getVarContentsText(tostring(v),"tostring(v)"))
		log(impaUtil.getVarContentsText(tostring(v.name),"tostring(v.name)"))
		log(impaUtil.getVarContentsText(tostring(v.corpse_expires),"tostring(v.corpse_expires)"))
	end
end
And this is the correpsonding log output:

Code: Select all

57233.601 Script @C:/Users/drahdi/AppData/Roaming/Factorio/temp/currently-playing/impaUtil.lua:104: Event 'on_player_died' triggered (Player 1)
57233.601 Script @C:/Users/drahdi/AppData/Roaming/Factorio/temp/currently-playing/impaUtil.lua:105: 
Variable name: eventData
{
  name = 41,
  player_index = 1,
  tick = 6680075
}
57233.601 Script @C:/Users/drahdi/AppData/Roaming/Factorio/temp/currently-playing/impaUtil.lua:110: 
Variable name: table_size(result) find_entities_filtered
1
57233.601 Script @C:/Users/drahdi/AppData/Roaming/Factorio/temp/currently-playing/impaUtil.lua:112: 
Variable name: tostring(k)
"1"
57233.601 Script @C:/Users/drahdi/AppData/Roaming/Factorio/temp/currently-playing/impaUtil.lua:113: 
Variable name: tostring(v)
"table"
57233.601 Script @C:/Users/drahdi/AppData/Roaming/Factorio/temp/currently-playing/impaUtil.lua:114: 
Variable name: tostring(v.name)
"character-corpse"
57233.602 Error MainLoop.cpp:1202: Exception at tick 6680075: Error while running command "cct": The scenario level caused a non-recoverable error.
Please report this error to the scenario author.

Error while running event level::on_player_died (ID 41)
Entity is not a corpse.
stack traceback:
	...ata/Roaming/Factorio/temp/currently-playing/impaUtil.lua:115: in function 'handler'
Last edited by Impatient on Sun May 10, 2020 9:55 pm, edited 1 time in total.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4059
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Plz help with "Entity is not a corpse." error on entity with name "character-corpse"

Post by boskid »

There are 2 prototype types: "corpse" and "character-corpse". They are different types, corpse_expires works only with entities of type "corpse".
Post Reply

Return to “Modding help”