Page 1 of 1

[0.17.21] Destroyed construction bot stops on_robot_built_entity propagation to other mods

Posted: Wed Mar 27, 2019 12:18 am
by Muppet9010
When 2 mods are both subscribed to the on_robot_built_entity event and a mod destroys the construction bot that did the building later called mods never receive the event.
I would expect the later mods to still receive the event, however, the referenced "robot" in the event table would be to a non-valid entity.

Test Setup
  1. Extract the 2 mod folders from the zip.
    Mod A will destroy() the construction robot that is referenced as "robot" on the on_robot_built_entity event.
    Mod B will print a message in-game on the on_robot_built_entity event. No event data is utilised in this to avoid any possible reference issues.
    mods.zip
    (1.01 KiB) Downloaded 52 times
  2. Put the save in place. It is just a player with power armor and construction robots setup.
    robot builder die test.zip
    (1.37 MiB) Downloaded 55 times
Test Without destroying robot - prove Mod B works
  1. Disable Mod A
  2. Enable Mod B
  3. Load the save
  4. Place a ghost small power pole
  5. The construction robot builds it
  6. Mod B will write an in-game message to confirm that the on_robot_built_entity has triggered.
Test destroying robot - show bug
  1. Enable Mod A & Mod B
  2. Load the save
  3. Place a ghost small power pole
  4. The construction robot builds it
  5. Mod A reacts to the on_robot_built_entity event and destroys the construction robot.
  6. Mob B does not write a message as it never received the event on_robot_built_entity. This is the bug.

Re: [0.17.21] Destroyed construction bot stops on_robot_built_entity propagation to other mods

Posted: Wed Mar 27, 2019 4:59 am
by DaleStan
Muppet9010 wrote: Wed Mar 27, 2019 12:18 amhowever, the referenced "robot" in the event table would be to a non-valid entity.
So, every mod needs to be prepared to receive events for invalid entities? This seems like a disaster waiting to happen. (One of the basic ground rules for programming is that all parameters must be valid. This applies both when you call into the system -- Factorio, in this case -- and when the system calls you.)

What is the real-world benefit of getting an on_robot_built_entity event with an invalid robot?

Re: [0.17.21] Destroyed construction bot stops on_robot_built_entity propagation to other mods

Posted: Wed Mar 27, 2019 8:41 am
by Klonan
This is how all events works, and not a bug

If you have an event execution problem, I would suggest to work with the other mod author to resolve it

Re: [0.17.21] Destroyed construction bot stops on_robot_built_entity propagation to other mods

Posted: Wed Mar 27, 2019 10:10 am
by Muppet9010
But the entity was built and still exists in the world. Just cause the builder is gone seems crazy for the event propagation to stop. The event still happened and the outcome is still valid despite the robot no longer existing. This is also inconsistent with other events that can have their referenced argument things deleted by other mods and still propogate fully.

There is no other event triggered that I can see for the entity appearing in the world that my mod should react to in this scenario. As the entity has still appeared and my mod wants to react to that, not the builder.


The other mod author has added a work around by delaying the destruction of the robot by a tick so I can react to the placed entity event. But this in itself seems ludicrous.


@DaleStan, yes the referenced arguments recieved through events must be checked if they are valid as other mods may have changed them already. This is known and expected and proper.

Re: [0.17.21] Destroyed construction bot stops on_robot_built_entity propagation to other mods

Posted: Wed Mar 27, 2019 10:29 am
by Rseding91
Muppet9010 wrote:This is also inconsistent with other events that can have their referenced argument things deleted by other mods and still propogate fully.
Incorrect. If any events required arguments are invalidated the event propagation stops.
Muppet9010 wrote:@DaleStan, yes the referenced arguments recieved through events must be checked if they are valid as other mods may have changed them already. This is known and expected and proper.
Incorrect. You never have to check event arguments - they are always valid if you get the event. You won't get the event if any required argument is invalidated.