event.entity.die(event.force) will always work, even if force is nil. force is optional in the event and for entity.die(), though in the damage event I don't think it can ever be nil (e.g. entity.damage() requires a force, normal damage comes from *something*)
event.entity.die(event.force, event.cause) won't always work, because if the second argument is present, it must be non-nil. The argument is optional, but can only be not present. It's not a big issue, but it makes for some extra logic, which is a bit ugly:
Code: Select all
local function on_entity_damaged(event)
local entity = event.entity
local force = event.force
local cause = event.cause
--special logic
if should_die then
--error without cause
--entity.die(force, cause)
if cause then
entity.die(force, cause)
else
entity.die(force)
end
end
end