Hello. I have noticed that there appear to be some inconsistencies between on_force_created and on_surface_created. The game only appears to fire on_force_created when a force is created through LUA, and so doesn't get fired when a new map is created with the three default forces. On the other hand, on_surface_created fires both when nauvis is created, and when a new surface is created through LUA. I would like to request that on_force_created also fire when the game itself makes a force, not just when one is created through LUA.
Additionally, in game, you can get players and surfaces by index number, but you can only get a force by name. I would like to request that game.forces should be able to accept a force's index number as an alternative to the force's name.
Thanks for your time!
Force event and lookup consistency
Force event and lookup consistency
Don't forget, you're here forever.
Re: Force event and lookup consistency
I believe the correct behavior is that on_surface_created shouldn't fire when starting a new game. If you need to run some logic on every surface/force/player/whatever, you are supposed to loop through the existing ones in on_init, then listen to new ones with the various events. This makes a lot more sense when you consider that the mod may be added part way through an existing game.Raiguard wrote: ↑Sun Jul 21, 2019 9:17 pmHello. I have noticed that there appear to be some inconsistencies between on_force_created and on_surface_created. The game only appears to fire on_force_created when a force is created through LUA, and so doesn't get fired when a new map is created with the three default forces. On the other hand, on_surface_created fires both when nauvis is created, and when a new surface is created through LUA. I would like to request that on_force_created also fire when the game itself makes a force, not just when one is created through LUA.
I just checked the source code, this seems to be already implemented, just not documented.
Re: Force event and lookup consistency
Indeed, this was added recently. I fixed the doc for the next version. If you find an event that doesn't provide a force index (only a force name) please let us know.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: Force event and lookup consistency
Unless I'm missing something on_surface_created does not fire when the default surface is created.
If you want to get ahold of me I'm almost always on Discord.
Re: Force event and lookup consistency
It doesn't and it's a sad discovery. It also doesn't fire in few other scenarios I think (like creation of surface in on_init of some mod.. maybe if it runs before your mod).
It basically means that this event is only marginally useful.
Re: Force event and lookup consistency
As explained in the Data Lifecycle page of the API, under "4. control.lua init":
If you want to fire events for your own mod to pick up, you need to manually call the function you have registered to the event within on_init.Note: until on_init has finished executing for a given mod (scenario scripts are also counted as a mod) the game will not raise any game events for that mod.
This was done so that you don't get events called before your global tables have been created in on_init. I'm not sure why events aren't raised from within your own on_init though. Personally i'd prefer if it would fire your events from inside your on_init. I've ran into several bugs that weren't easy to track down because of this behavior. Now i've written a wrapper for raise_event that checks if on_init has completed, and if not it will manually call all functions registered to the event manually.
Re: Force event and lookup consistency
Yes, turns out that I was wrong about the event firing when nauvis was created. I guess it's good to keep everything as-is. Thanks guys!
Don't forget, you're here forever.