Dilemma of mod events

Place to get help with not working mods / modding interface.
Post Reply
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 114
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

Dilemma of mod events

Post 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.

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Dilemma of mod events

Post 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.

User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 114
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

Re: Dilemma of mod events

Post 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)

Post Reply

Return to “Modding help”