Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Field Researcher
Original Poster
#1 Old 25th Oct 2020 at 7:25 PM
Default Using the same class across multiple mods
I'd like to use some of the classes I've created across multiple mods that can work either apart or together, and I want to be sure I'm understanding how to do that. Would I just put the class in my cross-mod namespace, and then make sure every mod I make that uses that class contains the same version of it, in the same namespace?
Advertisement
Space Pony
#2 Old 25th Oct 2020 at 7:41 PM Last edited by Battery : 25th Oct 2020 at 8:01 PM.
tere are multiple ways to achive this

1. Simple Solution: Make a common Base mod that supplies these classes and reference them in the other mods (this would be a strict requirement)
2. More Complex Solution you can use Reflection to check if a mod is installed and then call the methods you need through reflection aswell ( you can look at the Battery.RemoteUtil class from my C# Utility mod to check that functionality out) this has the advantage that each mod is independent of each other but has the disadvantage that calls to these methods will be much slower

E: and yes the version needs to be the same, so do you want a hard requirement or and optional implementation ?

E2:

heres how you would use it

The mod that supplies the Method
Code:
	public static class MyStaticClass
	{
		public static void CallMe(int a, string b)
		{
			Battery.UI.MessageUtil.WriteNotification(a + " " + b);
		}
	}



The mod that uses the method
Code:
			if(Battery.RemoteUtil.IsScriptModInstalled("Modname"))
			{
			   	Battery.RemoteUtil.InvokerUtil.InvokeStatic("...MyStaticClass","CallMe",100,"Test");
			 }
			


replace the ... with a qualified name
Field Researcher
Original Poster
#3 Old 25th Oct 2020 at 8:18 PM
Thanks for the reply, so fast!

Quote: Originally posted by Battery
do you want a hard requirement or and optional implementation ?


I think what I want is a hard requirement. I'd like to use the RelationshipManager and AttractionManager classes I made for the polyamory mod in an adoption mod too, to track relationships and prevent romance in families not recognized as related by the game; so the goal is to make those classes required for both mods, but the mods themselves able to stand apart from each other. So it sounds like your first solution, with the common base mod, is the way to go; Reflection is awesome but the slowness is an issue, yeah.

About the base mod - would including the .dll and instantiator XML for that in the package for each mod that needs it work?
Space Pony
#4 Old 25th Oct 2020 at 8:23 PM
You can just make your mods like you normally do.
make a new mod, add the basemod dll and work with it all other requirements still apply (instatiator for each assembly)
Back to top