Page 1 of 1

Dilemma of mod events

Posted: Mon Apr 05, 2021 8:57 pm
by ZwerOxotnik
There's a mod and I want to separate its functionality on ~2 mods with mod event compatibility. However, I noticed that they can be both optional to each other actually. So, it doesn't matter where the events will be between the 2 mods, because it's either breaks compatibility of mod events or makes one of mods dependent upon the other.

And, there's another solution which can bring other issues because of uncertain conditions. I can use a third mod which will have the mod events with its own remote interface to reveal the mod events.

1. Is it enough to only just reveal the mod events with some description?
Example below:

Code: Select all

local mod_events = {
  on_mod_event_1 = script.generate_event_name(),
  on_mod_event_2 = script.generate_event_name()
}

remote.add_interface("my-mod-interface", {
  get_event_name = function(name)
    return mod_events[name]
  end
})
2. Do I need to care about a case when none of mods/interfaces will request the mod events actually?

3. Did I forget something else?

(I don't know an elegant solution for migration or something like that in this case. Also, such solution can bring more problems with compatibility in some cases)
Although, I can create mod events and remote interfaces in each mod and use the third mod to support mod events between other mods and, probably, it's an over complex solution.

Re: Dilemma of mod events

Posted: Wed Dec 22, 2021 11:23 pm
by robot256
I found this old post looking for a different question, and it's interesting. Did you figure it out?

The problem is that you can't call mod B's "get_event_number" interface from mod A, *and* call mod A's "get_event_number" interface from mod B during loading, right? But you only need to do either of them if both mods are present. So a solution would be to put the interface in mod A, which both takes as an argument mod B's event number and returns mod A's event number. Then mod B optionally depends on mod A, and calls mod A's interface if it's there. Mod A registers the event handler for mod B's event during the interface function, and mod B registers the event handler for mod A's event after the interface function returns.

Re: Dilemma of mod events

Posted: Thu Dec 23, 2021 10:23 am
by ZwerOxotnik
robot256 wrote:
Wed Dec 22, 2021 11:23 pm
Did you figure it out?
I decided to create another mod without dependencies for the mods which will create all mod events in any case and serve all other mods without checking mods: https://mods.factorio.com/mod/EasyAPI (the concept is actually more different, since I decided to give to players and mods more access, control and solve some issues. It's still WIP, and I want to make new major feature in ~2 weeks)