Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

12 hours ago, katateochi said:

I'm still very new writing KSP plugins, when you say take a look at the definition, where should I be looking?

Both MonoDevelop and Visual Studio will show you the definition via autocomplete.. just start typing the name and it should pop up.  There may be a better way in the IDE to browse them, I don't know.

Most of the online documentation is out of date shortly after it's written/scraped.  The IDE is the best source of truth.  I just skim the online docs as a vague reference to find likely class names.

EDIT: I just saw that with1.2, there are official API docs!  Woohoo!  Check out https://kerbalspaceprogram.com/api/index.html

Edited by hab136
Link to comment
Share on other sites

2 minutes ago, kball said:

New to KSP modding and C#/Unity platform in general. Is there any good way to conditionally reference KSPUtil to maintain backward compatibility?

I don't think there's much reason to do that.  The API has changed, and you should really only be trying to build against one version of KSP.

Link to comment
Share on other sites

Ok, definitely down with that. Just wasn't sure if the references would break if building against 1.2 but running in 1.1.3. Should have tested that before posting, but testing now.

Edit: Doesn't seem like that works. So we need to branch our plugins for the new version? Can that be right?

Edited by kball
Link to comment
Share on other sites

18 hours ago, kball said:

Ok, definitely down with that. Just wasn't sure if the references would break if building against 1.2 but running in 1.1.3. Should have tested that before posting, but testing now.

Edit: Doesn't seem like that works. So we need to branch our plugins for the new version? Can that be right?

Yes, I also use a branch when I want to keep support of an old version, but it's often useless (I've only keep support of KSP 1.0.5 because KSP 1.1.X wasn't stable on GNU/Linux), with KSP 1.2, I think I can drop support of KSP 1.0.5.

On Monodevelop, when I read the Assembly-CSharp I see many private var which have strange character like a square with numbers. Can we access to these var with reflection?

Exemple: for my mod QuickHide I work on the ApplicationLauncher, I've read the new API doc and I've found this:

List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appList = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListHidden = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListMod = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListModHidden = new List<ApplicationLauncherButton>()
	private

and in Monodevelop I read this:

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> 	;

Source: https://kerbalspaceprogram.com/api/class_k_s_p_1_1_u_i_1_1_screens_1_1_application_launcher.html

Can I use appListMod in reflection?

Link to comment
Share on other sites

9 minutes ago, Malah said:

Yes, I also use a branch when I want to keep support of an old version, but it's often useless (I've only keep support of KSP 1.0.5 because KSP 1.1.X wasn't stable on GNU/Linux), with KSP 1.2, I think I can drop support of KSP 1.0.5.

On Monodevelop, when I read the Assembly-CSharp I see many private var which have strange character like a square with numbers. Can we access to these var with reflection?

Exemple: for my mod QuickHide I work on the ApplicationLauncher, I've read the new API doc and I've found this:


List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appList = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListHidden = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListMod = new List<ApplicationLauncherButton>()
	private
List<ApplicationLauncherButton> KSP.UI.Screens.ApplicationLauncher.appListModHidden = new List<ApplicationLauncherButton>()
	private

and in Monodevelop I read this:


private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> ;

private List<ApplicationLauncherButton> 	;

Source: https://kerbalspaceprogram.com/api/class_k_s_p_1_1_u_i_1_1_screens_1_1_application_launcher.html

Can I use appListMod in reflection?

Not according to the rules you can't. Refer to rule 7 of the Add-On rules:

A better question would be why? the API for the Application Launcher contains public methods and vars to facilitate a mod integrating into that class.

Edited by JPLRepo
Link to comment
Share on other sites

3 minutes ago, JPLRepo said:

Not according to the rules you can't. Refer to rule 7 of the Add-On rules:

A better question would be why? the API for the Application Launcher contains public methods and vars to facilitate a mod integrating into that class.

I wanted to use this var to access and hide others mods applauncher :wink:

At this time I use

ApplicationLauncherButton[] _appLauncherButtons = (ApplicationLauncherButton[])Resources.FindObjectsOfTypeAll (typeof (ApplicationLauncherButton));

 

Link to comment
Share on other sites

On 7/12/2016 at 9:09 AM, Papa_Joe said:

The reason I do not use the class @Tralfagar mentioned is 1)  It did not exist when these mods were created, and 2), it does not give me sufficient resolution for my needs.  The class works just fine, but does not give you the ability to pick a specific seat, nor does it allow for crew swaps.  In ShipManifest, I account for both.  Therefore I've continued to use the method similar to CrewManifest, but with several enhancements.  ShipManifest will allow seat to seat transfers within the same part, and part to part transfers (including swapping crew members if the seat/part is full in both cases).  Additionally, in Realism mode, I've also included sounds and a delay to simulate the time needed to move from part to part or seat.

Additionally, I've included support for ConnectedLivingSpace, When in realism mode and with CLS enalbled within SM, transfers now respect whether or not the parts have an internal connection to each other. if not, then the transfer must be accomplished by EVA.  hmm... you gave me an idea.  if you cannot transfer internally, I could change the xfer button to initiate an eva instead...

 

Update.  I've added the capability to send a Kerbal EVA in realism mode if CLS prevents an internal transfer.  I will be releasing this feature soon in a point upgrade.   thanks for giving me this great idea.

@Tralfagar feel free to look over and leverage any of the code you see of value in SM.  I hope it helps you in some small way.  

@Papa_Joe

I'm having an issue where I am getting the kerbal EVA'd, but need to eject him, ie:  not have him holding on to the ship.  

I'm using this:

FlightEVA.fetch.spawnEVA(kerbal, p, p.airlock)

but, when I do this:

 FlightGlobals.Vessels[i].rootPart.Rigidbody.AddForce(FlightGlobals.Vessels[i].rootPart.transform.up * ejectionForce);

it doesn't seem to do anything, the kerbal stays attached.

Any ideas?

Link to comment
Share on other sites

6 minutes ago, linuxgurugamer said:

Any ideas?

You can no longer use AddForce directly, you must do what it says in the thread about the changes in 1.2.

Search for AddForce.  Basically, you need to call Part.AddForce rather than calling the RigidBody directly.

Also, I suspect there is a better way to make him let go of the hatch than smacking him with an invisible hammer... :wink:

Edited by Padishar
Link to comment
Share on other sites

2 minutes ago, Padishar said:

You can no longer use AddForce directly, you must do what it says in the thread about the changes in 1.2.

Search for AddForce.  Basically, you need to call Part.AddForce rather than calling the RigidBody directly.

Thanks.

I'm resurrecting EVA Parachutes, and fixing a couple of problems also

Link to comment
Share on other sites

I am trying display a list of parts but when I try to use Part.partName it just says "Part" for all of them.

Here is what I have

using System;
using System.Collections.Generic;
using UnityEngine;
using KSP;

namespace AutoAbortSystem
{
    public class ModuleAAS : PartModule
    {
        List<ModuleAAS> AASmodules = new List<ModuleAAS>();
        List<Part> parts = new List<Part>();
        public void Start()
        {

        }

        public void Update()
        {
            parts.Clear();
            AASmodules.Clear();
            foreach(Part part in FlightGlobals.ActiveVessel.parts)
            {
                parts.Add(part);
                if (part.gameObject.GetComponent<ModuleAAS>()) AASmodules.Add(part.GetComponent<ModuleAAS>());
            }
        }

        public void OnGUI()
        {
            if(this == AASmodules.ToArray()[0]) GUILayout.Window(616173, new Rect(100,100,350,800), window, "Automatic Abort System", HighLogic.Skin.window);
        }

        public void window(int windowID)
        {
            foreach (Part part in parts)
            {
                if (part != this.part) GUILayout.Label(part.partName);
                else GUILayout.Label(part.partName + " (active)");
            }
        }

        public void OnDestroy()
        {
            AASmodules.Remove(this);
        }


    }
}

4W5v48y.png

Am I doing something wrong or is this a bug?

Link to comment
Share on other sites

5 minutes ago, JoePatrick1 said:

I am trying display a list of parts but when I try to use Part.partName it just says "Part" for all of them.

Here is what I have

<snip>

Am I doing something wrong or is this a bug?

You want the part.partInfo.title or part.name

Link to comment
Share on other sites

20 minutes ago, linuxgurugamer said:

Any idea how to have a partmodule on an unfocused ship (but still close by) to continue to work?

Normal update methods should be run for any part on a vessel within physics range.  Is there a case where that doesn't seem to be happening?

Link to comment
Share on other sites

Just now, blowfish said:

Normal update methods should be run for any part on a vessel within physics range.  Is there a case where that doesn't seem to be happening?

That's what I thought.  

I'm EVA'ing a number of kerbals, and having a chute open up after they eva.  It isn't working for some of them, so it's something in the code.

This is the EVA Parachute mod I'm reviving

Also, my understanding is that spawnEVA will spawn the kerbal and make the kerbal the active vessel.

Will this also happen if you do a spawnEVA on a vessel which isn't the active vessel?

Link to comment
Share on other sites

So right now, after using spawnEVA to send a kerbal out on EVA, I use an ejection force to get him away from the ship.  This has problems, mainly if the direction of the force happens to be into the ship, bad things happen (explosions, receding form Kerben at >40,000m/sec, etc).

I'd rather just have the kerbal let go, but haven't yet found how to do this.  Any ideas?

Thanks in advance

Link to comment
Share on other sites

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