LuaEntity.last_user can be nil on a LuaEntity returned from the game, but that field does not accept nil assign
Posted: Fri Oct 04, 2019 12:28 am
That is, trying to assign <LuaEntity>.last_user = nil throws an error, but LuaEntities returned via the scripting engine - such as find_entities_filtered - can have a nil value for that field.
This is bad on two fronts:
The first is that this makes no sense; if the game can give LuaEntities with nil value for last_user, that must be an acceptable value (ie causes no issues) for that parameter, and thus it makes no sense to forbid a nil assign.
The second problem is more practical: it means you cannot "clone" an entity directly; the entity that exists may not be allowed to be recreated with that exact data. Just copying all the entity data from one to another runs the risk of throwing an error, simply because one of the fields contains a value which is not permissible to assign to that same field.
Hell, you can throw an error by assigning an entity its own parameters: entity.last_user = entity.last_user will throw an error if the entity has a nil user, as some script-returned entities do.
This is bad on two fronts:
The first is that this makes no sense; if the game can give LuaEntities with nil value for last_user, that must be an acceptable value (ie causes no issues) for that parameter, and thus it makes no sense to forbid a nil assign.
The second problem is more practical: it means you cannot "clone" an entity directly; the entity that exists may not be allowed to be recreated with that exact data. Just copying all the entity data from one to another runs the risk of throwing an error, simply because one of the fields contains a value which is not permissible to assign to that same field.
Hell, you can throw an error by assigning an entity its own parameters: entity.last_user = entity.last_user will throw an error if the entity has a nil user, as some script-returned entities do.