Let me imagine a world where .destroy() and .create_entity() automatically raise events. That means that the simple codemrvn wrote: βThu Nov 28, 2019 11:42 am That was a deep look at the events. But what remains makes me wonder: Why doesn't the game raise the events already?
Any action taking by scripts that would normally raise an event when done by the player or C++ code should just raise the event when done by mods. Drop all the "script_raised_*" stuff. If knowing something was done by script is desired (and yes, it is) then add a field to the events "bool script_raised" or more flexible "string mod_name", which would be nil when not mod raised. If doing things without raising the events is desired/necessary then add an option to the action (e.g. create_entity) to be quiet.
So if some script like bluebuilt revives a ghost the C++ code automatically emits the right event. No need for the mod to do anything and therefore no need to have the raise_event with complex parameter checking. The cost for making that work right would be the addition of script_raised/mod_name to each event on the c++ side. Would that be easier?
for y=0,2 do
for x=0,2 do
game.player.surface.create_entity({name="crude-oil", amount=100000, position={game.player.position.x+x*7-7, game.player.position.y+y*7-7}})
end
end
can now crash your mod! The mod reacting to the event can delete the player or the surface and poop goes your mod. Or the mod just deletes the oil again, or it moves the player or teleports the player to a different surface or whatever. The result is that you don't get what you want. So, you will have to rewrite the command to account for that, perhaps by storing the surface and player position and checking .valid on the surface. That's only for a simple command like that. Imagine doing that in an entire scripting-heavy mod, like Factorissimo. Hell, I even already had enough difficulty handling raising events deleting surface/player in my damn simple Portals mod, and I know Mylon had to deal with mods deleting revived entities in Bluebuild. Or, just to give a concrete example, see this more than 1000 line commit just to deal with mods deleting the entity I just created.
TL;DR: Making raising events the default makes you have to handle all the bullshit other mods can do with the events.
As a side note, some things already automatically raise events, such as surface deletion and chunk deletion.