Page 1 of 1

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
by Reika
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.

Re: 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 3:19 am
by Rseding91
Thanks for the report. It's now fixed for the next version of 0.17.

Re: 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 6:28 am
by Reika
Rseding91 wrote:
Fri Oct 04, 2019 3:19 am
Thanks for the report. It's now fixed for the next version of 0.17.
As in nil is now a valid assign?

Re: 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 6:43 am
by Bilka
Reika wrote:
Fri Oct 04, 2019 6:28 am
Rseding91 wrote:
Fri Oct 04, 2019 3:19 am
Thanks for the report. It's now fixed for the next version of 0.17.
As in nil is now a valid assign?
Yes.