Skip to content

2: Interacting with other mods

Miron Alexandru edited this page Dec 24, 2021 · 1 revision

Retrieving a loaded mod

You can retrieve a mod that's currently loaded by using Mod.GetMod(string).

Mod otherMod = GetMod("OtherModNameIDHere");

if (otherMod != null)
{
    // Get entries
    ItemEntry someItem = otherMod.GetItem("SomeItemModIDFromOtherMod");

    // Call special API from mod
    OtherModClass otherModAPI = otherMod as OtherModClass;
    otherModAPI.DoCoolStuff();

    // ...and other things.
}
else
{
    // Oh no, mod is not loaded right now!
    throw new InvalidOperationException("Where is my cool mod API?!");
}

Defining dependencies

If you depend on some other mod (you want to use an API it offers, or something), it's a good idea to define a mod dependency.

You can do so by adding a ModDependencyAttribute to your mod class.

[ModDependency("GrindScript", "0.16", true)]  // Depends on GrindScript, version 0.16 or higher (this is also the mod tool version)
[ModDependency("OtherModNameIDHere", "0.13", false)]  // Depends on this mod, version 0.13 *exactly*
[ModDependency("AThirdModID")]  // Depends on this other mod. Any version will do
public class TestMod: Mod
{
    public override void Load()
    {
        Mod otherMod = GetMod("OtherModNameIDHere");

        // Do stuff with otherMod
    }

    public override void Unload() { }
}

Important points about mod dependencies:

  • On mod load, GrindScript checks if the dependencies exist in the mod folder
  • Mods which don't have all of their dependencies satisfied will be prevented from loading
    • The same thing happens when a dependency was found but it threw an exception during load
  • A mod will load after all of the mods it depends on are loaded

Clone this wiki locally