Jump to content

C#/KSP question


Recommended Posts

I looking to learn some more about the environment, to improve my current mods and write some new ones.

I've used and seen the following, but don't have a clear explanation:

[KSPScenario(ScenarioCreationOptions.AddToAllGames, new GameScenes[] { GameScenes.SPACECENTER, GameScenes.EDITOR, GameScenes.FLIGHT, GameScenes.TRACKSTATION })]
[KSPField(isPersistant = true)]
[KSPAddon (KSPAddon.Startup.EditorAny, false)]

 

Can someone point me to some documentation which will explain these (and any others)?  I've been looking, but obviously haven't used the right searches

Thanks in advance

Link to comment
Share on other sites

Those are attributes. I don't have a good understanding of them either, but the basic idea seems to be that they further define or categorize the method or field following each attribute.

So the [KSPField] attribute is used for all Part Modules and Scenario Modules to collect each value into their respective Fields lists (BaseFieldList, I think; [KSPEvents] and [KSPActions] work the same way, with a BaseEventList and a BaseActionList). It makes for a convenient tag for saving and loading data, displaying information in a part's right-click menu, or telling a Part Module what values to look for in the config file.

[KSPAddon] just tells KSP to start a Unity MonoBehaviour that the attribute is attached to. It's useful for mods that don't have a part or scenario module (you need something to tell your code to actually start doing something). I'm not really sure what the MonoBehaviour is attached to, there's probably some KSP controller class that is the parent of all KSPAddon classes.

[KSPScenario] is, as far as I know, only used once, the first time you start a game with an addon using that Scenario Module (and it only seems to be read in the Space Center scene, which is why you can't skip that scene when loading new mods with Scenario Modules). After that KSP's Scenario Module controller loads all of the data from the save file, and as long as there is a matching class that inherits from Scenario Module it will be handled properly. It isn't actually necessary to use [KSPScenario] to add your Scenario Module, it's just much simpler than the other options.

The only other KSP-specific attribute that I'm aware of is [Persistent], which gets used when manually saving and loading data.

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