[Solved] Plz help with "Entity is not a corpse." error on entity with name "character-corpse"
Posted: Sun May 10, 2020 9:23 pm
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
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'