Jump to content

IConfigNode and InternalModule


Recommended Posts

Try as I might, I could not get IConfigNode-type KSPFields to work in InternalModule at all. I'm not sure why, and no amount of voodoo managed to even get OnLoad to run. No amount of searching resulted in an answer on what I could possibly be doing wrong, people generally don't write much InternalModules, and they're apparently having problems getting KSPField/IConfigNode to work in regular parts as well, there are very few examples of published source using it.

I have, nevertheless, stumbled onto an amusing roundabout method to get the functionality anyway, which I present here in case anyone tries to google for one:



// Every config file is loaded in the GameDatabase tree of ConfigNodes.
// We can just ask the GameDatabase for all PROP config nodes -- i.e.
// configurations of all props.
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes ("PROP")) {
// And then we can find the prop we live in by name, since prop names
// are meant to be unique.
if (node.GetValue ("name") == internalProp.propName) {
// So this is the configuration of our prop after it got loaded. Nice place.
// We know it contains at least one MODULE node, us.
// And we know our moduleID, which is the number in order of being listed in the prop.
// Therefore the module section by that number is our module's own config node.
ConfigNode ourConfigNode = node.GetNodes ("MODULE") [moduleID];
break;
}
}

Upon which, ourConfigNode contains the root ConfigNode for our module configuration and from there on it's smooth sailing parsing out the section you couldn't get at with a KSPField.

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...