Soft-depending mods

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

Soft-depending mods

by Nore » Tue Apr 09, 2013 16:54

Something that could be useful for lots of mods would be a softdepends.txt file in the mod folder: mods that are listed in it are loaded before the mod if they exist, but else, they are ignored.
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Tue Apr 09, 2013 17:29

You can use lua to check wheter a certain mod is installed and change your script's behaviour:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 if minetest.get_modpath("streets") then
  print("Streets is installed")
 else
  print("Streets isn't installed")
 end

I don't think that a softdepend.txt is needed.
Last edited by webdesigner97 on Tue Apr 09, 2013 17:29, edited 1 time in total.
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Tue Apr 09, 2013 17:32

Yes it is, because we sometimes want to execute the code after the other mod in that case (for example in the older versions of mesecons, or if we want to call code in the other mod). Of course, the mod will still call that to know if it should run the code.
 

User avatar
stu
Member
 
Posts: 737
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11

by stu » Tue Apr 09, 2013 17:41

webdesigner97 wrote:You can use lua to check wheter a certain mod is installed and change your script's behaviour:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 if minetest.get_modpath("streets") then
  print("Streets is installed")
 else
  print("Streets isn't installed")
 end

I don't think that a softdepend.txt is needed.


I don't think that is reliable at 'load time' since it appears that mods load in a particular order (probably ascii). Consequently mod 'A' may not be able to detect the presence of mod 'B' until both mods are loaded.

Edit, actually modpath should be still readable, I am thinking of using function calls or static data from other mods.

Please ignore..
Last edited by stu on Tue Apr 09, 2013 17:44, edited 1 time in total.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Tue Apr 09, 2013 18:21

Yes. This would be nice. OR, a way to register a callback that will be made once a named mod is loaded (or called immediately if it is already loaded, or called never if it isn't present). This would eliminate the possibility of introducing circular dependencies where A tries to load after B and B tries to load after A (or A -> B -> C -> A or even more complicated patterns) although it would also require slightly more event-driven thinking. For example, here is how a pair of mods might look with a soft dependency loading order:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
---- Mod A
A = {}
function A.foo(...) ... end

---- Mod B (automatic soft depend on mod B)
A.foo(...)


and here is how it might look with a mod loaded callback:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
---- Mod A
A = {}
function A.foo(...) ... end

---- Mod B
local function aCallback(param)
   A.foo(...)
end
minetest.register_on_mod_loaded("A", aCallback, param)


There are two things worth noting about that example:
  • aCallback may never be called, or may be called right away if mod A is already loaded, so mod B needs to be designed so that either order would work.
  • Since aCallback is never called if mod A isn't loaded, it is free to lookup the global symbol A (which we know is defined by mod A) without testing whether it actually exists.

Mod B in the second example could also look like this, but I wanted to be able to name the function when talking about the behavior:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
---- Mod B
minetest.register_on_mod_loaded("A", function(param) A.foo(...) end, param)
Last edited by prestidigitator on Tue Apr 09, 2013 18:23, edited 1 time in total.
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

by Sokomine » Tue Apr 09, 2013 18:25

get_modpath seems to be reliable; it just doesn't solve the mentioned problem. Sometimes you have to execute your own code *after* the other mod finished. For example, I want to plug into the tree-growing functions of moretrees. That's difficult to do if those functions are not defined yet because my mod was loaded first. All I could do would be to delay execution of my mod for a few seconds and hope it won't get needed in the meantime.
The callback method prestidigitator suggested would be very helpful.
A list of my mods can be found here.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Wed Apr 10, 2013 12:34

 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

by Sokomine » Wed Apr 10, 2013 20:05

When I turned my mod into a modpack, it seems it got executed first :-(. Anyway, doing a callback with 0 seconds as suggested in the thread rubenwardy mentioned may work but isn't exactly a clean soulution.
A list of my mods can be found here.
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 4 guests

cron