Deadlock989 wrote: ↑
Wed Jun 05, 2019 1:16 pm
I don't believe there is. I might be wrong - I only just found out yesterday that you can have hidden
optional dependencies by using (?).
That's a nice one!
If there isn't, your best bet is to detect whether the mods are present using mods, and then do something if none of the optionals are actually present. You could halt the load with error() and a message directing the player to go and install the preferred mod. But this would also present the default option of disabling your mod, which isn't a terrible thing but a minor irritant.
I guess disabling my mod would be OK -- no use loading it unless it does something, and it can't do anything if the other mods are missing.
Other than that, you're left with chat messages on game load to warn that the mod isn't doing anything because none of its optional dependencies are present.
I played with that, too, but I can't get it to work.
I can read game.active_mods from on_init() and on_configuration_changed(), so it's trivial to print a message to the player when a new save game is created or once when a save file is loaded that previously didn't contain the mod
or when the configuration changed in some way. However, I would also need on_load(), which triggers every time a save file is loaded except for the instance when a mod is loaded into a save file that it previously wasn't part of
-- but LuaGameScript is not available in this event.
No problem, I thought. Each mod also has access to its own instance of the global table, so I could check for active mods in data-updates.lua and set a flag, like "global.req_mods_active=true". Then I'd just act on this value in on_load() from control.lua. Great idea -- except in on_load(), you don't have access to global, so global.req_mods_active will always be nil. Unless I overlook something, there is no way to get the list of active mods when loading a normal save.
Doing the check in on_load() does seem necessary, though. Say, you start a new game with only my mod and mod A installed, or you add my mod to a game where only mod A was installed before. In this case, on_init() would trigger and print a reminder to the player's chat console that my mod is useless without B and C. Player ignores this message, save file is overwritten some time later. Next time the game is loaded, my mod is already part of the game, so on_init() won't be called ever again until player changes the configuration or adds/removes mods. With on_load(), I could remind the player every time the game is loaded -- if I could somehow get the information on which mods are installed into the control stage. (Of course, that would also be spamming, but that's another topic!)