Jump to content

PartModule accessing values from part.cfg


Recommended Posts

how do i access a field from the part.cfg? i want to be able to use the same module for several parts and have the part.cfg contain some values for them.

part.cfg


PART
{
// ...
MODULE
{
name = MyPartModel
mySpecialValue = 50;
}
// ...
}

so far i've found nothing that makes any sense what so ever. all i can find are partial examples of IConfigNode classes and i can't even follow how that's supposed to get loaded or where? and nothing i've done with the [KSPField] has done anything (other than saving data in the persistent file and displaying gui stuff on the context menu)

is there a simple example of loading a value from the config file into the PartModule? this just seems like it should be such a basic thing but i can't find anything but people asking how to do it and no real examples.

Link to comment
Share on other sites


PART
{
MODULE
{
name = MyPartModel
mySpecialValue = 50;
}
}

As the part.cfg file with the part.


public class MyPartModel : partModule
{
[KSPField]
public float mySpecialValue;
}

will set the variable mySpecialValue to 50. Note that KSPField has several options, such as if it shows on the GUI, is it persistent, etc. This is just a bare-bones example.

D.

Link to comment
Share on other sites

is there anything that could potentially break that? i've had it setup as a [KSPField(guiActive = true, guiName="Max Resource Types")] and it doesn't load the value from the config file. i've tried having it an int and a float. i've tried grabbing it from the ConfigNode that gets passed to the OnLoad.

ok. so i just made a really simple class with nothing else to test this and it worked for that one. i guess if all else fails i just have the other module load the values i need. :/

edit: it's not working anywhere for me now....

edit again: ok now it's working. i have no idea why it wasn't working before. the only real change is now isPersistant = true.... but i'm sure i tried that before. ah well.

thank you for your help. :3

Edited by catgirltech
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...