Page 1 of 1

in on_entity_died for worm turrets, cause is nil

Posted: Tue May 23, 2017 4:02 pm
by Mylon
Summary:
Worm turrets do not report their cause on death.

Observed behavior:
event.cause is nil

Expected behavior:
event.cause is player (or turret, or car, or whatever)

To recreate:
Start a game and run these commands:

Code: Select all

/c game.player.surface.create_entity{name="small-worm-turret", position={50,0}}
/c script.on_event(defines.events.on_entity_died, function(event) game.print(event.cause) end)
Now go kill the worm (cheating may help)
Console prints: "nil"

Expected behavior: Lua error (trying to pass a non-string to game.print)

Re: in on_entity_died for worm turrets, cause is nil

Posted: Sat Jun 03, 2017 8:16 pm
by Rseding91
This is because worms don't die immediately when they reach 0 health but go through an animation stage.

"cause" is optional because it's not always available. This is one of those instances where it's not available.

Re: in on_entity_died for worm turrets, cause is nil

Posted: Tue Apr 02, 2019 5:50 am
by Solinya
Bit of a gravedig because I've been investigating a change in mod behavior in 0.17.23.

For much of the 0.17.x branch, up through at least 0.17.17, even though event.cause is technically optional, it was being populated correctly for worm deaths. Now I'm finding on 0.17.23, worm turrets call on_entity_died with a nil cause.

Is it an intentional change to no longer populate the cause on worm turret deaths? And since it was working before, did something change that made that prior population no longer feasible?

Re: in on_entity_died for worm turrets, cause is nil

Posted: Tue Apr 02, 2019 7:01 am
by darkfrei
Rseding91 wrote: Sat Jun 03, 2017 8:16 pm This is because worms don't die immediately when they reach 0 health but go through an animation stage.

"cause" is optional because it's not always available. This is one of those instances where it's not available.
How to disable this lag between starting of death and end of death? Units have that death animation too, but dying immediately.