Jump to content

How to use ConfigNode?


Recommended Posts

  • 2 weeks later...

A ConfigNode is more less a section as you see them in the save games (.sfs). Example:

ROSTER
{
  KERBAL
  {
    name = Jebediah Kerman
    gender = Male
    type = Crew
    trait = Pilot
    brave = 0.5
    dumb = 0.5
    ...
    CAREER_LOG
    {

You can think of ROSTER as a config node. It has a title (ROSTER) and children in the form of values (none in this case) and nodes. The child nodes in this case are config nodes titled KERBAL.

You can think of KERBAL as a config node. It has a title (KERBAL) and children in the form of values (name, gender, type, trait, ...) and nodes (in this case we can see one called CAREER_LOG).

One of the cool thing about part module config nodes is that Module Manager can find and manipulate the nodes.

 

Edit:

:confused: Here I wanted to give a simple explanation, and then I run into trouble myself (https://forum.kerbalspaceprogram.com/index.php?/topic/166271-part-confignode-persistence-of-upgradesapplied/).

 

Edited by Rodhern
Oops, maybe I better fix my own code first :-)
Link to comment
Share on other sites

If you know which values and child nodes you are looking for you can do it a bit easier. I, on the other hand, have a fondness for the idiot proof method.

You can run foreach on ConfigNode.values which will give you all the values of the node as key-value-pairs of type ConfigNode.Value (edit: which in turn has ConfigNode.Value.name and ConfigNode.Value.value).

You can run foreach on ConfigNode.nodes which will give you all the direct child nodes (as ConfigNodes).

Just run the foreach recursively and you will soon have traversed the tree.

Edited by Rodhern
added more detail
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...