Jump to content

Where is the KSP Addon/Plugin API Documentation? � or "how do I even get started?"


Recommended Posts

Hopefully I'm blind, but...

Where is the KSP Addon/Plugin API Documentation?

...no, I don't mean this...

...or these...

...or even the sticky...

...I mean, REALLY...where is the documentation about...

What functions/events/methods can I call/catch/use?

...I have read some source code of other mods, so I do know a little more than I'm letting on, but really: how did all the current Plugin Authors LEARN THE API to begin with???...how can you learn the KSP API when there are little-to-no docs about it?

Example...

OK, the wiki page...

...says this...

Vessel ActiveVessel { get; }

The vessel currently being controlled by the player.

...that's great, but 1st of all, is FlightGlobals.ActiveVessel a function?...or a property?...or a method?...which way do I "get the value from it?"...

vessel = FlightGlobals.ActiveVessel
vessel = FlightGlobals.ActiveVessel.get()
vessel = FlightGlobals.ActiveVessel()
vessel = FlightGlobals.ActiveVessel("some magic unknown param")

...but once I do get a copy of the active vessel, what ELSE can I do with it? In PHP terms, I need the output of a print_r(vessel) to be able to SEE what properties/methods/whatever are available off the vessel object...where is the documentation for this?

Basically, I'm trying to learn C# (C-Pound), Unity & the KSP Plugin API...all at the same time. I need to know which syntax (when I'm looking at other plugin's code) is C#, which "things" are part of the Unity API (which there IS Documentation for) & which "things" are part of the undocumented KSP API.

I might wanna make this a separate topic for the following, but...

What changed, in the Addon/Plugin API, between KSP 0.22 & 0.23?

...I'm trying to revive a plugin, that I didn't write. It works fine in KSP 0.22, but fails to do almost anything in KSP 0.23. To fix it, I need to know "what changed between KSP 0.22 & 0.23?"...but not just the normal user-facing "changelog", I need the developer-facing "what in the API changed?"...since I can't really find any KSP API Docs (the links above are not good enough/complete...or I wouldn't be posting for help).

I understand if the KSP Addon/Plugin API Docs are incomplete or yet-to-be-written, but then, again: if there are no Docs, how did all the current Plugin Authors LEARN THE API to begin with???...how did anyone learn to write a plugin for KSP without any Docs?...how can you call/use a function, if you don't know it exists?...once you do (somehow) call a function, how can you use the return value, if you don't know the details of what type of object it returns?

I know that some of what I need to learn is in the Unity API Docs...that's fine...but I need to know where Unity ends & KSP begins. I need to know the KSP-specific API, that is the mystery.

Plugin Authors: you can help me, if you post a link to a diff of what you changed to make your addon compatible with KSP 0.23. I want several diffs of what various addons HAD TO CHANGE to make their addon work again in KSP 0.23...but more than just the diffs: how did you find out that you needed to change those things...how did you know what to change, without docs?

All of this is about the Ceko Labs Rangefinder mod...it was only written/last updated for 0.21.1...I have confirmed that it "works" (but I may not have tested everything) in KSP 0.22...& for no reason at all it DOESN'T WORK in KSP 0.23. This is my dilemma, I don't know where to start fixing it. I don't know why it worked, I don't know why it stopped working. I'm not even sure I should try to fix it...or simply write my own plugin from scratch?...my end goal is not to have a PART plugin, I want a PARTLESS plugin to show the Real Altitude...but the Ceko Labs Rangefinder mod, even tho it requires a part, is the closest mod to my goal. So, I need to fix it so it will work at all, then I can tinker with it, to hopefully make it not need a part.

Link to comment
Share on other sites

I feel your pain :)

There is no official documentation, but there are some tools to help with itincluding:

- several posts on the forum (not always up to date)

- The irc chat #kspmodder if I recall well, on esper.net

- Taranis have offer some very simple up to date code (http://forum.kerbalspaceprogram.com/threads/56053-Example-plugin-projects-to-help-you-get-started)

What functions/events/methods can I call/catch/use?

...I have read some source code of other mods, so I do know a little more than I'm letting on, but really: how did all the current Plugin Authors LEARN THE API to begin with???...how can you learn the KSP API when there are little-to-no docs about it?

When you import the dll on your project, you can see the available functions that you can access, after it's a matter of trial, look at other codes, and asking.

Example...

OK, the wiki page...

...says this...

...that's great, but 1st of all, is FlightGlobals.ActiveVessel a function?...or a property?...or a method?...which way do I "get the value from it?"...

vessel = FlightGlobals.ActiveVessel
vessel = FlightGlobals.ActiveVessel.get()
vessel = FlightGlobals.ActiveVessel()
vessel = FlightGlobals.ActiveVessel("some magic unknown param")

...but once I do get a copy of the active vessel, what ELSE can I do with it? In PHP terms, I need the output of a print_r(vessel) to be able to SEE what properties/methods/whatever are available off the vessel object...where is the documentation for this?

This is C# syntax, it mean you can access the ActiveVessel as a "Variable" in read only (they are called accessor)

Basically, I'm trying to learn C# (C-Pound), Unity & the KSP Plugin API...all at the same time. I need to know which syntax (when I'm looking at other plugin's code) is C#, which "things" are part of the Unity API (which there IS Documentation for) & which "things" are part of the undocumented KSP API.

Just like you I learned C# with modding for KSP, but I have a strong c++ background and a friend who helped me a lot as it's his everyday job to code with those language.

I would especially advice to start learning c# with modding ksp, unless you are extremely motivated and patient. (there is no debug, documentation etc....)

I might wanna make this a separate topic for the following, but...

What changed, in the Addon/Plugin API, between KSP 0.22 & 0.23?

Every update break some mods due to change on some functions! also it is important to recompile the mod with the UnityEngine and CSharpAssembly dll that come with the new version.

...I'm trying to revive a plugin, that I didn't write. It works fine in KSP 0.22, but fails to do almost anything in KSP 0.23. To fix it, I need to know "what changed between KSP 0.22 & 0.23?"...but not just the normal user-facing "changelog", I need the developer-facing "what in the API changed?"...since I can't really find any KSP API Docs (the links above are not good enough/complete...or I wouldn't be posting for help).

Since there is no doc and debug you need a extensive use of Debug.Log, and look at the Log in game or the file.

In the config file change VERBOSE_DEBUG_LOG to True

I understand if the KSP Addon/Plugin API Docs are incomplete or yet-to-be-written, but then, again: if there are no Docs, how did all the current Plugin Authors LEARN THE API to begin with???...how did anyone learn to write a plugin for KSP without any Docs?...how can you call/use a function, if you don't know it exists?...once you do (somehow) call a function, how can you use the return value, if you don't know the details of what type of object it returns?

I know that some of what I need to learn is in the Unity API Docs...that's fine...but I need to know where Unity ends & KSP begins. I need to know the KSP-specific API, that is the mystery.

In Visual studio (I am pretty sure other IDE works the same) you can browse the function of the DLL you reference to your projects. And of course there is a lot to learn with how Unity manage the GameObject and all that.

Plugin Authors: you can help me, if you post a link to a diff of what you changed to make your addon compatible with KSP 0.23. I want several diffs of what various addons HAD TO CHANGE to make their addon work again in KSP 0.23...but more than just the diffs: how did you find out that you needed to change those things...how did you know what to change, without docs?

Most of the work are about recompiling the addon. if your addon is very specific, and the update change what your addon is using (let says terrain for scansat etc...) you will need to figure out what changed and how to make it work (irc and forum are best for that).

All of this is about the Ceko Labs Rangefinder mod...it was only written/last updated for 0.21.1...I have confirmed that it "works" (but I may not have tested everything) in KSP 0.22...& for no reason at all it DOESN'T WORK in KSP 0.23. This is my dilemma, I don't know where to start fixing it. I don't know why it worked, I don't know why it stopped working. I'm not even sure I should try to fix it...or simply write my own plugin from scratch?...my end goal is not to have a PART plugin, I want a PARTLESS plugin to show the Real Altitude...but the Ceko Labs Rangefinder mod, even tho it requires a part, is the closest mod to my goal. So, I need to fix it so it will work at all, then I can tinker with it, to hopefully make it not need a part.

I would start by making a partless addon using Taranis templates. Once you have it working, then i would look at how the mod found the real altitude, and implement it in the game.

good luck

Link to comment
Share on other sites

As Ubio said, there's nothing. Welcome to the black parade.

We all learned to mod this way, your best tools are other people's source code. It's all over the palce. Feel free to look and learn, but be careful about copyright if you're going to copy paste some of it, plagiarism is still a thing.

Else really it's typical C#. FlightGlobals.ActiveVessesl {get;} is most obviously a proprety, since it's using the get keyword.

Now generally you don't need to change anything when versions update. You only need to if something you used changed. Example: for .24, I expect every mod who plays wih part joints, like KJR and IR to have to do major reworks of their code depending on how much joints changed.

It's all a matter of looking at what your log says, to find what is causing errors, and how to fix it. It's probably as good as it gets to debug KSP.

Link to comment
Share on other sites

When you import the dll on your project, you can see the available functions that you can access...

...actually, I'm not using an IDE...I'm simply using Notepad with the csc.exe compiler.

also it is important to recompile the mod with the UnityEngine and CSharpAssembly dll that come with the new version.

...yup, that info I was able to find. How to compile was the easy part, after finding that the csc.exe was installed by default with every .NET version.

In the config file change VERBOSE_DEBUG_LOG to True

...this may help.

In Visual studio (I am pretty sure other IDE works the same) you can browse the function of the DLL you reference to your projects.

...unfortunately, I'm not using Visual Studio or any IDE, which may be part of my problem. Instead of using an IDE, I'd just like a text file or HTML page listing the stuff the IDE would tell me, like every function in every DLL, for a start. Can someone dump that info for me?...or is there a command I can run (without installing the full IDE) to dump the DLL info?

...you will need to figure out what changed...

...& that is why I'm here. There really is no Developer Changelog for what changed in the API between versions? That's sad. They know what changed & it should be simple for them to say "hey, if your using ABC.XYZ, you need to update to DEF.GHI". They have a changelog for USERS, why not Devs/Modders?

I would start by making a partless addon using Taranis templates.

...yes, I did stumble on Taranis's templates before & those were some of the best things I found when searching.

Once you have it working, then i would look at how the mod found the real altitude...

...the Rangefinder mod uses a Raycast to find the distance. I plan on using the RealChute way of getting the Altitude & making sure that it's really reliable...it's reliable enough for him, so it should be good enough for me.

Does anyone know how to hijack the built-in Altimeter & force it to display a different number???...what could possibly be the API for that?...maybe I need to hook its OnUpdate() event/method & prevent it from updating, so I can update it myself?...but how? How do I get a "handle" to the Altimeter? How do I override it's OnUpdate()? (or whatever method it uses to update) How do I change the numbers manually/myself? I'd like something simple, like GameObject.Find("Altimeter").setAllitude(12345)...but I don't think it'll be that easy...I don't even know its real name, if it's called "Altimeter" or something else...Anyone know where I can find the names of built-in objects?

FlightGlobals.ActiveVessesl {get;} is most obviously a proprety, since it's using the get keyword.

...I wouldn't say most obviously...since that syntax is foreign to me (I'm new to C# {but not programming in general}), particularly the "{ get; }" part...I don't know what those braces & the word "get" mean/signify in C# syntax, since I've never coded in C#. If that entire "{ get; }" part wasn't even there, then I wouldn't be confused...it would simply be a property, since there's no parens to signify it being a function, but the get part is really confusing...you don't actually call it like "FlightGlobals.ActiveVessel.get" or "FlightGlobals.ActiveVessel.get()", so why is get there?

You only need to if something you used changed.

...since I'm trying to fix someone else's code, I need to read every line to even know what is used.

It's all a matter of looking at what your log says...

...oh, yes, I know about the logs. I did that 1st, there were no errors, no logs for this particular problem: the mod just isn't working in 0.23...you add the part to the ship, Launch & nothing happens...no flood of errors for why it's not working, nothing. The part just sits on the ship & doesn't work (no altimeter overlay). I would love for there to have been errors in the log to fix.

I'm particularly happy you replied, stupid_chris, cuz just a couple days ago I was looking at your RealChute Parachute Systems mod...the changelog says...

December 18th 2013

v0.3.2

KSP 0.23 compatibility update!

...after seeing that, I ran to your source code, so I could generate a diff of version v0.3.1 to v0.3.2...alas, those versions are not on GitHub...so I couldn't find out what you needed to change to make it work.

More replies welcome...the more info the better!!!

Link to comment
Share on other sites

It helps to understand how the layers underneath KSP work.

Unity is the game engine. There is a fair bit of documentation for Unity, although it's not stellar. Manipulation of the game world typically happens through Unity, so often you can write a plugin with little to no knowledge of KSP's internals.

C# is the programming language, and .NET is the framework. They're not hard, but they're also not at all similar to PHP. For example, C# is a statically typed language, so you can use a tool to inspect an assembly (DLL) and discover what types, methods, et cetera are available.

I encourage poking around to discover how things work, and indeed, the greatest "advances" in modding happen that way. But there's no point in reinventing the wheel, so take advantage of the resources that do exist. You linked a number already, and I'll throw in the #kspmodders IRC channel. The forums are great for introductory information and common questions, and IRC is great for when you have a really specific question. (You might get an answer like "do it with this general method" and then be expected to figure that general method out on your own; your mileage may vary. The channel often ignores simpler questions that can be answered elsewhere.)

Link to comment
Share on other sites

Is there any reason for not using Visual Studio (or some similar non-windows program)? The object browser is immensely helpful when trying to track down what does what. At the very least in will tell you what methods and variables are available in each class. Generally the names are self-explanatory so you just need to search for something that sounds like what you need.

And if you're searching for differences between versions you could load up references to old KSP versions and check the relevant classes. The available code is not always clear, but I think sifting through object browser and checking others' source code are the only real options when it comes to figuring out how things work (and obviously google for things not necessarily KSP specific).

Link to comment
Share on other sites

...after seeing that, I ran to your source code, so I could generate a diff of version v0.3.1 to v0.3.2...alas, those versions are not on GitHub...so I couldn't find out what you needed to change to make it work.

I made no changes. All I had to do was recompile the plugin with the new Unity and KSP dlls with the changes I made over the weeks prior to it, but that I've been holding on for the release.

As I said, there's nothing to change if nothing you used changed.

If the plugin isn't working, find what isn't working and rewrite it. It might be much simpler to simply built it back from scratch though. And do get an IDE, it'll help immensely, and will probably underline a few deprecated components.

Link to comment
Share on other sites

I'm not going to lie. Your going to spend hours and hours trying to figure things out. That's including looking at other people's code. And using you definitions to scour through the code to find things. It takes a lot of time and effort.

Some of the more knowledgable moders are usually willing to help. As this thread has already shown. But again a lot of your time is spent finding out how things work.

Link to comment
Share on other sites

By the way one of the biggest changes in .23 was adding a string code to editor lock and engine fx change. At least stuff that effected my code. Sure ther was more. Most changes seem to be certain code getting its own methods.

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