I've run into small inconsistency with this event.
Documentation states that it's not called for nauvis since that surface exists from the start.
I have encountered a case where it's not called when surface is created by game.create_surface call. It seems that event doesn't fire when Oarc mod is creating it's surface during on_init event.
Is that a planned behavior?
on_surface_created event question
Re: on_surface_created event question
Don't mind me, read below (in case anyone comes across this later).
Last edited by eduran on Wed May 08, 2019 7:16 pm, edited 1 time in total.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: on_surface_created event question
Have a counterexample:eduran wrote: ↑Wed May 08, 2019 6:14 pmMost events only trigger when the base game does something and not off of mod scripts. If a mod creates a surface and want others to notice, it has to use script.raise_event. If the mods in questions don't do that you are not going to see the event. So yes, that is working as intended.
Code: Select all
/c script.on_event(defines.events.on_surface_created,function(e) game.print('created!') end) game.create_surface('test')
@orzelek:
Is *your* mod before or after that other mod in the load oder? /c game.print(script.get_event_order())
If it is *after* the other mod then *you* don't get the event, because a while ago (like a year ago :p) there
was a change that made it so that no mod can recieve *any events* before it's own on_init has been called.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: on_surface_created event question
My mod would be after - no dependencies present and alphabetically it's oarc-mod vs rso-mod.eradicator wrote: ↑Wed May 08, 2019 6:23 pmHave a counterexample:eduran wrote: ↑Wed May 08, 2019 6:14 pmMost events only trigger when the base game does something and not off of mod scripts. If a mod creates a surface and want others to notice, it has to use script.raise_event. If the mods in questions don't do that you are not going to see the event. So yes, that is working as intended.The base game never creates new surfaces, and there are no other events that are only used with script.raise_event, except for the three explicitly named ones.Code: Select all
/c script.on_event(defines.events.on_surface_created,function(e) game.print('created!') end) game.create_surface('test')
@orzelek:
Is *your* mod before or after that other mod in the load oder? /c game.print(script.get_event_order())
If it is *after* the other mod then *you* don't get the event, because a while ago (like a year ago :p) there
was a change that made it so that no mod can recieve *any events* before it's own on_init has been called.
That could explain why I don't get the event at all.. and it just means even more if's in strange places in my code.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: on_surface_created event question
You can simulate the event by calling your own handler in on_init.
Code: Select all
script.on_init(function()
--stuff
--more stuff
for _,surface in pairs(game.surfaces) do
rso_on_surface_created_handler_thingy{
name = defines.events.on_surface_created,
tick = game.tick,
surface_index = surface.index
}
end
end)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: on_surface_created event question
I've ended up just checking it anyway in few more places... which leads me to conclusion that in current state this event is less then useful.
Since there is no guarantee that it will be called for each new surface then we can't rely on it to initialize any per surface data structures. This means that any method that expects this data to exist needs to still include a check for it's presence. So we might as well skip the event completely and rely on ongoing checks.
Since there is no guarantee that it will be called for each new surface then we can't rely on it to initialize any per surface data structures. This means that any method that expects this data to exist needs to still include a check for it's presence. So we might as well skip the event completely and rely on ongoing checks.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: on_surface_created event question
From what i understand about the engine my method posted above (raising it for all surfaces in your own init) *does* guarantee it gets called for all surfaces.
And if it does not than that problem persists for almost any event (tech_researched, entity_built, etc...).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: on_surface_created event question
I've ended up doing that but in mods changed event and in on init. I'm not sure what happens if you add a mod to game that will create surface in it's own on_init. And doing that on mods update was needed for other reasons too - like potential resource list changes.eradicator wrote: ↑Wed May 15, 2019 7:16 amFrom what i understand about the engine my method posted above (raising it for all surfaces in your own init) *does* guarantee it gets called for all surfaces.
And if it does not than that problem persists for almost any event (tech_researched, entity_built, etc...).
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: on_surface_created event question
If your mod was already in the savegame then your mods on_init() has already been run and you should recieve the event just fine. (As the non-recieving is entirely based on your own on_init() *not* having been called yet.)
But ofc it won't hurt to do it in on_config() too. I just didn't wanna see you drop into the hell where you can't rely on any events at all anymore ;p.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.