on_script_built_entity + raised by surface.create_entity
Posted: Fri Aug 24, 2018 9:02 pm
Hello!
while working on a mod i ran into something which i think could be improved.
i want to create an entity from another mod, however the entity is rather complex and consists of more than one entity. (i want to spawn in a nixie tube https://mods.factorio.com/mod/SantasNixieTubeDisplay, which is actually a lamp+arithmetic-combinator+ a lot of scripting).
so i want the other mods event handler to be fired, which surface.create_entity doesn't do.
I would like to see one more event: on_script_built_entity, with one event parameter created_entity of type entity.
and i would like surface.create_entity to automatically call it.
Now there are some workarounds to get this running now, but i think it is overall a bit of a mess.
I can raise on_built_entity or on_robot_built_entity myself using script.raise_event(event, table), however that isn't really great since i may not always know a good player_index and likely don't have an itemstack either. Also having a robot entity present is probably a rare use case.
I could raise script_raised_built, but (almost) no one really uses it (according to google /github), and for good reason:
since its argument are unspecified i cannot expect anything from it. and i can't expect any calls either. It would only work in a close collaboration between two modders, or a community consensus, both of which are unlikely.
By having a on_script_built_entity with the filled entity, most users can still combine the callbacks together (on_built_entity+on_robot_built_entity+on_script_built_entity handled in one function) as long as only they only care about the entity.
Modders who know their scripts are not meant to handle scripted construction can omit to handle it as well.
while working on a mod i ran into something which i think could be improved.
The use case:
i want to create an entity from another mod, however the entity is rather complex and consists of more than one entity. (i want to spawn in a nixie tube https://mods.factorio.com/mod/SantasNixieTubeDisplay, which is actually a lamp+arithmetic-combinator+ a lot of scripting).
so i want the other mods event handler to be fired, which surface.create_entity doesn't do.
The proposal:
I would like to see one more event: on_script_built_entity, with one event parameter created_entity of type entity.
and i would like surface.create_entity to automatically call it.
The workarounds:
Now there are some workarounds to get this running now, but i think it is overall a bit of a mess.
I can raise on_built_entity or on_robot_built_entity myself using script.raise_event(event, table), however that isn't really great since i may not always know a good player_index and likely don't have an itemstack either. Also having a robot entity present is probably a rare use case.
I could raise script_raised_built, but (almost) no one really uses it (according to google /github), and for good reason:
since its argument are unspecified i cannot expect anything from it. and i can't expect any calls either. It would only work in a close collaboration between two modders, or a community consensus, both of which are unlikely.
Some rationale:
By having a on_script_built_entity with the filled entity, most users can still combine the callbacks together (on_built_entity+on_robot_built_entity+on_script_built_entity handled in one function) as long as only they only care about the entity.
Modders who know their scripts are not meant to handle scripted construction can omit to handle it as well.