Cephei

The official unoffical "help a fellow plugin developer" thread

Recommended Posts

10 minutes ago, haselnuss said:

Is it possible to update my plugin while KSP is running to test a new version?

There is something somewhere on the forum that allows that for some specific cases. But in the end it is easier to have a copy of KSP with few parts and no Internals that loads fast.

Edited by sarbian

Share this post


Link to post
Share on other sites
11 hours ago, haselnuss said:

Is it possible to update my plugin while KSP is running to test a new version?

Yes:

There's a comment that says it still works in 1.2 pre.  I haven't used it lately but I used to use it a lot.

I wholly agree about having a separate KSP instance for development with only the bare minimum installed (and graphics tuned down), but even that can get frustrating to constantly reload.

Share this post


Link to post
Share on other sites

Does anyone know how to get the in-editor call back functions to fire, like void OnEditorAttach() ? Mono claims there is a link, but it doesn't seem to do anything. I am just try to write a debug string to the debug console for testing.

 

nvm figured it out, now I am working on getting isMirrored to give me a valid result.

hmm, is seems that ismirrored is set after attachment, that is not so useful.

Edited by Electr0ninja

Share this post


Link to post
Share on other sites
23 hours ago, enneract said:

I'm trying to create a vessel on the launchpad from the spacecenter or editor scenes.

I think I'm on the right track with ShipConstruction.PutShipToGround, but I'm having trouble locating the correct Transform for the second argument.

The following Gist demonstrates the issue; has anyone else tried doing something like this or run into a similar problem?

Gist

I can do it from flight... Vessel mover does something like this.  Take a look if that might help.

Share this post


Link to post
Share on other sites

The isMirrored member doesn't do anything in the editor currently, may be a bug idk, but I even set up a 1 second time delay thread so I could check the value after the OnEditorAttach() function was done. And nothing, it seems that the isMirrored member may never actually get set at all. Might just be dead code.

Share this post


Link to post
Share on other sites

And the next problem, I can't solve myself. I want to run some code, if KSP or the user adds, modifies or removes stages in the VAB. What I found is the class GameEvents.StageManager. This class contains the following functions:

  • GameEvents.StageManager.OnStageAdded
  • GameEvents.StageManager.OnStageRemoved
  • GameEvents.StageManager.OnStageSequenceModified

Are this the functions I am looking for?

How do I use them? The code below is not working and I do not understand the error message, my IDE shows me.

void Awake()
{
   GameEvents.StageManager.OnStageAdded(eventStageAdded);
}

private void eventStageAdded()
{
   //do something
}

 

 

Share this post


Link to post
Share on other sites
7 hours ago, haselnuss said:

How do I use them? The code below is not working and I do not understand the error message, my IDE shows me.

You need to call .Add() and pass your delegate to that, and then work out what parameters the delegate expects to be passed (I just define the delegate with no params and then see what error it throws, in this case it wanted an int).

void Awake()
{
 	GameEvents.StageManager.OnGUIStageAdded.Add (eventStageAdded);
}

private void eventStageAdded(int e)
{
	//do something
}

(also check out .Remove() to unbind your listener)

Share this post


Link to post
Share on other sites
On 9/30/2016 at 1:19 PM, Papa_Joe said:

I can do it from flight... Vessel mover does something like this. Take a look if that might help.

I'm specifically need to avoid going to flight to do this. :/ 

If I have to do it in flight, I need to figure out how to fake the icon on the launchpad indicating a craft ready to launch. 

Share this post


Link to post
Share on other sites
8 hours ago, enneract said:

I'm specifically need to avoid going to flight to do this. :/ 

If I have to do it in flight, I need to figure out how to fake the icon on the launchpad indicating a craft ready to launch. 

No problem.  I did not fully understand your use case

Share this post


Link to post
Share on other sites
1 hour ago, Anase Skyrider said:

I'm making a program in Visual Studio using C#. I need to be able to export the source code as per the rules of the forum. Can anyone help me?

Simplest way is to just include the entire project folder in the download (or as a separate download).

Share this post


Link to post
Share on other sites
4 hours ago, blowfish said:

Simplest way is to just include the entire project folder in the download (or as a separate download).

If that's the simplest way, then what are the other ways?

Share this post


Link to post
Share on other sites
16 minutes ago, Anase Skyrider said:

If that's the simplest way, then what are the other ways?

Many plugin developers post their code on Github, which is great but git itself has quite a learning curve.

Share this post


Link to post
Share on other sites
Just now, blowfish said:

Many plugin developers post their code on Github, which is great but git itself has quite a learning curve.

I didn't mean places to put the code, but rather, ways of exporting the code. Were you suggesting that I put the project files on Github?

Share this post


Link to post
Share on other sites
28 minutes ago, Anase Skyrider said:

I didn't mean places to put the code, but rather, ways of exporting the code. Were you suggesting that I put the project files on Github?

All the source code files are in the project directory.  The Visual Studio project just knows about all the files and how to compile them.

Share this post


Link to post
Share on other sites

How to use USI and Scansat modules for contracts

Suppose that a player uses the USI MKS/OKS and Scansat mods. Let us say KSP version 1.2, in case Kerbnet is relevant for any of my questions.

I would like to program a mission/contract that determines that the player has detected, say, a large patch of "Substrate" on Kerbin, or Eve for that matter. Then the goal of the contract is to build a small outpost in the vicinity.

Are there any good tutorials for mod interoperation? If not, can you give short answers to these questions:

1) If the player uses USI MKS/OKS and Scansat, there will be "Substrate" in the player's game, right?
2) How do I refer to/manipulate the community resource "Substrate"? Maybe via Kerbnet?
3) Can I determine which patches of "Substrate" the player has discovered?
4) If my plugin mission refers to (USI) "Substrate" and the quantities discovered (Scansat), how will the license terms of either USI MKS/OKS or "community resource pack" influence my license selection possibilities? (Scansat is straight forward; attribution where it is due)
5) If the answer to "4)" is that I can make an all rights reserved license, is it a nice thing to do, or is it frowned upon, given that the inspiration source is 'creative commons' protected?

Share this post


Link to post
Share on other sites

I've got something odd with the process of adding a button to the toolbar.  I'd been working against pre-release build 1473 and it was working as expected, but I've just moved up to 1564 and am now getting odd behaviour. 
I've got 2 toolbar buttons; 
One is set to appear in the VAB/SPH with the 7th arg to AddModApplication() being given as; ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH
That one works as expected, button only shows up in the editors.

The other button which should just appear in the space center scene has it's 7th arg given as just ApplicationLauncher.AppScenes.SPACECENTER
but it is being shown in the spacecenter, both editors and in flight.
The really odd thing is that if I change it to have 
ApplicationLauncher.AppScenes.SPACECENTER | ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH,
The it stops showing up in flight (but obv appears in the editors, which I don't want).

I'm either doing something daft or maybe there's an issue with 1564 and the toolbar? Can anyone confirm?

Edited by katateochi

Share this post


Link to post
Share on other sites
1 hour ago, katateochi said:

I've got something odd with the process of adding a button to the toolbar.  I'd been working against pre-release build 1473 and it was working as expected, but I've just moved up to 1564 and am now getting odd behaviour. 
I've got 2 toolbar buttons; 
One is set to appear in the VAB/SPH with the 7th arg to AddModApplication() being given as; ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH
That one works as expected, button only shows up in the editors.

The other button which should just appear in the space center scene has it's 7th arg given as just ApplicationLauncher.AppScenes.SPACECENTER
but it is being shown in the spacecenter, both editors and in flight.
The really odd thing is that if I change it to have 
ApplicationLauncher.AppScenes.SPACECENTER | ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH,
The it stops showing up in flight (but obv appears in the editors, which I don't want).

I'm either doing something daft or maybe there's an issue with 1564 and the toolbar? Can anyone confirm?

I'm having no issues with AppLauncher. perhaps if you supply a link to your code and have you checked your log for errors?

Share this post


Link to post
Share on other sites
21 hours ago, JPLRepo said:

I'm having no issues with AppLauncher. perhaps if you supply a link to your code and have you checked your log for errors?

I'm not getting any errors in the logs.  
I made a stripped down version of my toolbar initializer code to test and I'm getting the same odd things happening.  I've put that code in a gist here https://gist.github.com/Sujimichi/23cf077d89bc15acdc3c889cd39ac638
With that setup, when I first get to the space center both buttons are shown (expected: just button 2).  Then when I go into the VAB just button 1 is shown (as expected).  Then when going to launch button 2 shows up again (expected: no buttons). Then when I revert to the VAB both buttons are shown (expected: just button 1), then when going back to the space center from there just button 2 is shown (as expected).  Then!! going back to the main menu, button 1 shows up! (not at all expected!). And then finally when re-loading the save and going back to the space center, both buttons are shown twice.

Can't see anywhere in the logs showing the call to remove the buttons.  I'm clearly doing something spectacularly wrong here! Halp requested! 

Share this post


Link to post
Share on other sites

I'm wondering if anyone can tell me what Orbit.ObT does, and if and how it relates to Orbit.getObtAtUT and/or Orbit.getPositionAtUT. 

According to the docs Orbit.Obt is "time on this orbit (since periapsis)." But I'm not really clear on how that relates to the other two functions.

SCANsat has a check in its background scanning method for a negative Orbit.Obt:

	if (o.ObT <= 0)
    		goto dequeue;

It basically short-circuits the background scanning for a vessel.

In 1.2 SCANsat was having some spotty results when scanning at even moderate timewarp, around 100 - 1000X. I can "fix" the problem by removing this check, vessels were periodically ending the loop this way during part of their orbit, but I'm assuming this check was in there for a reason (I've always been wary of touching the background scanning mechanism as I don't really understand how it works :confused:).

Share this post


Link to post
Share on other sites
On 06/10/2016 at 3:20 AM, katateochi said:

I'm not getting any errors in the logs.  
I made a stripped down version of my toolbar initializer code to test and I'm getting the same odd things happening.  I've put that code in a gist here https://gist.github.com/Sujimichi/23cf077d89bc15acdc3c889cd39ac638
With that setup, when I first get to the space center both buttons are shown (expected: just button 2).  Then when I go into the VAB just button 1 is shown (as expected).  Then when going to launch button 2 shows up again (expected: no buttons). Then when I revert to the VAB both buttons are shown (expected: just button 1), then when going back to the space center from there just button 2 is shown (as expected).  Then!! going back to the main menu, button 1 shows up! (not at all expected!). And then finally when re-loading the save and going back to the space center, both buttons are shown twice.

Can't see anywhere in the logs showing the call to remove the buttons.  I'm clearly doing something spectacularly wrong here! Halp requested! 

Sorry ran out of time to look at your code.
But have you looked at this guide?

 

Share this post


Link to post
Share on other sites
On 07/10/2016 at 1:35 AM, DMagic said:

In 1.2 SCANsat was having some spotty results when scanning at even moderate timewarp, around 100 - 1000X. I can "fix" the problem by removing this check, vessels were periodically ending the loop this way during part of their orbit, but I'm assuming this check was in there for a reason (I've always been wary of touching the background scanning mechanism as I don't really understand how it works :confused:).

I changed all the parameters for Orbit to be -X..X instead of 0..2X (X may be pi or period/2) for consistency and slightly (1 bit) better precision. In the past, ObT was always 0..period for elliptical orbits (and -Inf..Inf for hyperbolic trajectories), but now ObT is -period/2..period/2 (meanAnomaly, eccentricAnomaly and trueAnomaly are now -pi..pi instead of 0..2pi). ObT is indeed time since periapsis, so -ObT -> -since = until.

I don't know if it is of interest to you, but there is now also meanMotion: the "velocity" of meanAnomaly (meanAnomaly = meanMotion * ObT), which holds for all orbit types.

I hope that helps.

(btw, the change is mentioned in the changelog)

Share this post


Link to post
Share on other sites

With the integrated settings using GameParameters.CustomParameterNode, is there any way to refresh an IList parameter? (I want to use the value of one setting to restrict the list values)

Edited by Crzyrndm

Share this post


Link to post
Share on other sites
2 hours ago, Crzyrndm said:

With the integrated settings using GameParameters.CustomParameterNode, is there any way to refresh an IList parameter? (I want to use the value of one setting to restrict the list values)

No, the ValidValues method is only called when the UI is built.  The closest you can come (short of hacking the unity objects) is to enable/disable fields dynamically.

Share this post


Link to post
Share on other sites
On 08/10/2016 at 11:35 AM, JPLRepo said:

Sorry ran out of time to look at your code.
But have you looked at this guide?

I had been following that guide and it talks about GameEvents.onGUIApplicationLauncherReady and GameEvents.onGUIApplicationLauncherDestroyed as events to listen to to bind methods to add and remove the buttons. So I'd subscribed to those events but what I was seeing was the Ready event was being fired on every scene change but I wasn't seeing the Destroy event fire at all. 
I then looked at some other mods (KerbalAlarmClock in particular, thanks @TriggerAu) and saw the use of onGameSceneLoadRequested as an event to bind the removal of buttons to.  So I added that Event and set the same button removal method as the Destroy Event would call to it and presto, everything is working as expected. 
So that seems to be sorted!

I have another Q, and sorry for re-asking it, but; how can I check if a craft in the editor has unsaved changes?
(the hacky solution I mentioned before is unreliable, as expected with hacky solutions!)

Share this post


Link to post
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.