Jump to content

Can you get values from other mods?


Recommended Posts

I want to know the delta V of each stage, and the total drag force.  MechJeb and AeroGUI compute these numbers.  Is there some way my mod could grab it from them?  Would that be easier than implementing the functionality myself?

This is for a mod that I'm just running locally on my machine.  How would I get hold of the object created by each plugin, the object that contains the values?

Link to comment
Share on other sites

Two ways:

1) Make a hard reference to the other mod, similar to how you add KSP libraries as a hard reference. Coding is reasonably clear and direct, but the other mod has to be installed or your mod will break. You may also have to update every time the other mod does
2) Reflection. Nowhere near as easy/intuitive from a programming perspective, but other functionality of your mod can continue to function if the dependency is not fulfilled. This is how mods like PWings manage to continue to work whether you have FAR installed or not
 

Which method to use depends on what you're doing. Reflection is generally favoured for additional functionality, while a referenced .dll is more for a core dependancy

Link to comment
Share on other sites

The third way is if they have been tagged as KSPFields for GUI display or save/loading, you can easily get them.

First, you have to check the source code for the actual object name, then input it as follows:

PartModule pm = Part.Modules["OtherModsPartModule"];
int fetchedvalue = (int)pm.Fields.GetValue("Value");

This is technically the Reflection method Crzyrndm mentioned, however Squad has provided these shortcuts for us, at least on objects tagged as KSPFields.

D.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...