Jump to content

Cross Mod Function Calls


eXecator

Recommended Posts

Hi all,

 

I'm looking for a way for a Mod to call into another Mods code.

 

Currently the best thing I came up with is to abuse something like X2AbilityTemplate and one of its delegates like BuildNewGameStateFn, but thats as hacky as it gets.

 

Is there a cleaner way to do this? Idealy i would like to reference an Interface definition from another package. That should be enough to get it of the ground.

Link to comment
Share on other sites

This will involve hard coding the name of the other mod's class, right? So it definitely won't work if the other mod is not installed. Fortunately both steam and nexus give you a way to indicate that one mod requires another; but I am not sure if it is possible to enforce that. So if the player ignores/misses your advice and runs yours without theirs, something bad will probably happen like a crash.

 

Any class can create an instance of another class like this:

 

CharGen = `XCOMGAME.spawn( class 'XGCharacterGenerator' );
CharGen.GenerateName(0, 'Country_Mec', strFirst, strLast);

Also you can refer to data members of existing classes like this:

 

NameStruct.MaleNames = class'DLA_AR_MecNames'.default.m_arrMecFirstNames;

Both of these lines are working for me in their context, but I don't know how all these things work in all contexts.

Link to comment
Share on other sites

In your example CharGen would have to be declared like

local XGCharacterGenerator CharGen

How would this declaration look like in case of an unknown class? If we do something like this

local object CharGen

how will we be able to access members like GenerateName?

 

Do we know how classes with the same name from different mods are treated? What will happen if Mod1 and Mod2 both define a class C and in Mod3 I run:

`XCOMGAME.spawn( class 'C' );

To overcome those problems we would need something like fully qualified names for those classes, like Mod1.C vs Mod2.C. Is that a thing?

Link to comment
Share on other sites

Sorry, maybe I don't understand what you want to do. I thought you had found another mod with a class function you wanted to call. In that case you would certainly know the exact names.

 

Good question about how the game would handle two mods that both defined the same class name. One of the first guidelines I read was that each modder should prefix their new class with their initials and the initials of the mod, to reduce the chance of this collision. I have done this, so each class I make in my Alien Rookies mod is named like DLA_AR_OriginalClassName.

Link to comment
Share on other sites

Sorry, maybe I don't understand what you want to do. I thought you had found another mod with a class function you wanted to call. In that case you would certainly know the exact names.

 

Thats fine, lets go with that exact usecase. Lets say you made SuperMod and it contains

class Awesome extends object;

static function BestEver()
{
  // ....
}

How would i call that nice function from my Mod?

Edited by eXecator
Link to comment
Share on other sites

From the code standpoint, it seems the same as the example I gave:

 

local Awesome a;

a = `XCOMGAME.spawn( class 'Awesome' );

a.BestEver(...)

 

From the ModBuddy standpoint, I am not sure how you would tell ModBuddy to use the compiled script files from the Awesome mod when compiling. And of course I highly doubt your compiled script would work for a player who did not have Awesome installed.

Link to comment
Share on other sites

From the ModBuddy standpoint, I am not sure how you would tell ModBuddy to use the compiled script files from the Awesome mod when compiling

 

Yeah, thats the thing. :-(

 

I would need to include a reference to some other mod into my project to access a foreign type.

Edited by eXecator
Link to comment
Share on other sites

It's not very clean, but I'm pretty sure you could have the author of the second mod include a copy of the class definition(s) in the initial mod; one of them would win the naming conflict based on the load order, and as long as they're the same version of the class definition it shouldn't matter too much which one wins.

 

That isn't ideal, but I don't think unrealscript has any way to do reflection so I doubt you could use other exploratory means to find a class and call its members if it isn't actually declared at compile time in your mod.

 

Hmm... thinking about it more, maybe there's a way to pass an abstract class definition to mod authors, then have them search for an instance of it as a gamestate object that you've got attached somewhere and call members on it using the abstract class's member signatures. There will still be a naming conflict, but it'll just be the abstract class definition rather than the concrete object that you create in your base mod. You could also version the "interface" by renaming the abstract class whenever the member signatures change so that naming conflicts are always between the same "interface" version.

Edited by Lucubration
Link to comment
Share on other sites

Thats basicaly copying the code over to the calling site.

 

I'm mainly interested in offerering other mods the option to get called from mine. They could maybe register a delegate or something for that reason. So copying the code over is not an option in this case. I would have to update my mod for every mod that wants to use it. :-(

Link to comment
Share on other sites

You haven't explained very much about what you are trying to do, or at least I don't understand it. In the base game, there are a bunch of different kinds of templates, and for each one a template manager. Mods can add a new instance of the template, such as adding a new soldier class, without needing to change the template manager. Maybe what you are describing is a new type of template manager. This just puts the shoe on the other foot. Their mods would have to reference yours, in order to get the manager.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...