Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

My first thought is that I think OnLoad runs before Start doesn't it?

In my (limited) understanding of how unity works, Awake() runs when an object is created, then OnLoad runs to load values, (insert other methods I'm forgetting about here), then once everything is ready, Start runs as the first Update frame, then Update and FixedUpdate take over.

So are you referencing something that is not created until the Start method runs maybe?

All the help I can offer, I've not done anything like what you are trying.

D.

Hey Diazo. Turns out it was (as usual) some mundane detail. The problem was here:


project.node = ResearchAndDevelopment.Instance.GetTechState(processor[0]);

The techID was being read into processor[1], not processor[0]. I switched them by mistake when cleaning up the OnSave() code that writes them to file.

Moral of story: I need to triple check my variables before posting!

Link to comment
Share on other sites

Hey guys,

I'm stuck on a problem while writing a mod and now I would like to ask if you can help me, because searching through internet didn't solve anything.

I have an event, where I want to unboard a Kerbal out of the current vessel and get the unboarded kerbal as a vessel to teleport to current body surface.

It also should be possible to teleport a Kerbal from the surface up to the vessel and re-board him.

The problem at this point is, that I don't know how to board or unboard a Kerbal by code.

Do you guys have any suggestions how to solve this?

Best regards,

Fanatorium

Link to comment
Share on other sites

@Fanatorium: Your question is too broad unfortunately, all I can do is point you towards Hyperedit to reference for the teleport part and something like TAC Life Support for interacting with Kerbals.

@_selfishPerson: Which buttons are you talking about? The Abort/Light/Gear/Brake buttons? You need to monitor the state of the associated action group for those. Do you mean the Recovery button? I think there is an OnVesselRecoveryRequest event?

Hope that helps,

D.

Link to comment
Share on other sites

@Fanatorium: Your question is too broad unfortunately, all I can do is point you towards Hyperedit to reference for the teleport part and something like TAC Life Support for interacting with Kerbals.

@_selfishPerson: Which buttons are you talking about? The Abort/Light/Gear/Brake buttons? You need to monitor the state of the associated action group for those. Do you mean the Recovery button? I think there is an OnVesselRecoveryRequest event?

Hope that helps,

D.

Thanks! Yeah, the break buttons. But specifically the button, not when the key is pressed. Found it too!

FlightUIController.fetch.brakes.OnPress += OnPress;

(in your Start()) will attach the OnPress on the breaks to you event. You can then filter on right click after that. Thanks anyways!

Link to comment
Share on other sites

It is, but you won't get much help here if you use VB

No. There is no need to know the format if you want to add info to the save from the game, the game provide plenty of method to add section to the save without knowing the format.

Link to comment
Share on other sites

it is how far in the queue you want your call to be placed. Use 0 or 1, it should be fine.

But what are you trying to do that require a post draw call ?

It's just how I've always known to draw a window - is this wrong? I'm guessing it is since you question it haha

Link to comment
Share on other sites

It's one way, the other being directly using OnGUI (the queue is just an array of Callbacks each called inside OnGUI). OnPostDraw has the advantage of syncing with KSP's show/hide UI without any extra effort (otherwise you have to listen to the show/hide events), but does suffer from style interaction and is probably more vulnerable to exceptions in others also using the same queue

Edited by Crzyrndm
Link to comment
Share on other sites

It's one way, the other being directly using OnGUI (the queue is just an array of Callbacks each called inside OnGUI). OnPostDraw has the advantage of syncing with KSP's show/hide UI without any extra effort (otherwise you have to listen to the show/hide events), but does suffer from style interaction and is probably more vulnerable to exceptions in others also using the same queue

Oh right! I see. It's a very simple mod so I think I'll stick to it but thanks for the tip!

Link to comment
Share on other sites

@Fanatorium: Your question is too broad unfortunately, all I can do is point you towards Hyperedit to reference for the teleport part and something like TAC Life Support for interacting with Kerbals.

Thanks for your reply, Diazo. I'll take a look on TAC Life Support.

And my question may be a bit too broad, you're right.

This is the essential part of my question: How to unboard (go on eva) and board (get back from eva to cockpit) a kerbal by code.

Best regards,

Fanatorium

Link to comment
Share on other sites

  • 2 weeks later...

Trying to integrate my For science mod with the stock toolbar, and I must admit that I understand about jack squat as to what is going on with GUI stuff. (Not that I know much to begin with.)

I'm getting this error, which I can only assume means my toolbar didn't load.

"[Warning]: ApplicationLauncher already exist, destroying this instance"

I don't have a whole lot of code behind the toolbar yet, I just want the durned thing to show so i can finally work with something I can see in action.


private void Start()
{
if ((HighLogic.CurrentGame.Mode == Game.Modes.CAREER | HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) & !initStyle) InitStyle();

RenderingManager.AddToPostDrawQueue(0, OnDraw);
GameEvents.onGUIApplicationLauncherReady.Add(OnGuiAppLauncherReady);
GameEvents.onGUIApplicationLauncherDestroyed.Add(OnGuiAppLauncherDestoyed);
}

private void OnDestroy()
{
GameEvents.onGUIApplicationLauncherReady.Remove(OnGuiAppLauncherReady);
GameEvents.onGUIApplicationLauncherDestroyed.Remove(OnGuiAppLauncherDestoyed);
}

private void OnGuiAppLauncherReady()
{
if (FSAppButton == null)
{
FSAppButton = ApplicationLauncher.Instance.AddModApplication(

toggleCollection,
toggleCollection,
null,
null,
null,
null,
ApplicationLauncher.AppScenes.FLIGHT,
GameDatabase.Instance.GetTexture("FS_icon", false)
);
}
}

private void OnGuiAppLauncherDestoyed()
{
if (FSAppButton != null)
{
ApplicationLauncher.Instance.RemoveModApplication(FSAppButton);
FSAppButton = null;
}
}

I tried following the guide posted and look at examples, but I couldn't find a clean solution that would work for me. I am quite certain I am doing something stupid at this point, but I don't know what else to try.

The way I understand it, I'm supposed to "register" the events OnGuiAppLauncherReady() and OnGuiAppLauncherDestroyed(), creating and destroying my instance of the toolbar, and to create an instance with AddModApplication().

The rest of the mod works and it compiles just fine. I just get that error, and no toolbar button.

If anyone knows what to do, or can point me to a guide or example in idiot language, I would be forever grateful. I'm not a professional programmer, so the jargon is hard to understand.

Edited by WaveFunctionP
Link to comment
Share on other sites

Squad seems to have changed exactly when the events get fired which led to a lot of people's buttons getting broken. I don't bother fiddling with the GUI events at all:

System.Collections.IEnumerator Start()
{
while (!ApplicationLauncher.Ready) yield return 0;

// install button
}

Link to comment
Share on other sites

Trying to integrate my For science mod with the stock toolbar, and I must admit that I understand about jack squat as to what is going on with GUI stuff. (Not that I know much to begin with.)...

The onGUIApplicationLauncherReady event only fires now when you go from the Mainmenu to the Spacecenter and the launcher gets ready, simlarly for the not ready message - fires when you return to the Main menu

Thats the reason, xEvilReeperx's code is close to what I do, I simply check if the ApplicationLauncher.Ready is true and then add the button, if it aint ready in the Flight scene it aint gonna be ready ever :)

Heres my code module I use fr the applauncher if you want another reference - https://github.com/TriggerAu/TransferWindowPlanner/blob/master/TransferWindowPlanner/SharedStuff/AppLauncher.cs

Link to comment
Share on other sites

The onGUIApplicationLauncherReady event only fires now when you go from the Mainmenu to the Spacecenter and the launcher gets ready, simlarly for the not ready message - fires when you return to the Main menu

Thats the reason, xEvilReeperx's code is close to what I do, I simply check if the ApplicationLauncher.Ready is true and then add the button, if it aint ready in the Flight scene it aint gonna be ready ever :)

Heres my code module I use fr the applauncher if you want another reference - https://github.com/TriggerAu/TransferWindowPlanner/blob/master/TransferWindowPlanner/SharedStuff/AppLauncher.cs

I was actually looking at your code earlier. You are firing off your app initialization in the onGUIApplicationLauncherReady() method. (You do an check there for ApplicationLauncher.Ready.) So, I'm a bit confuzzled. I can copy that exact structure and it won't work for me, and unless I'm misunderstanding you (i probably am), then neither should yours.

I can put my button in Awake() and it works just fine. I get a button. However, I start getting duplicate buttons when switching vessels though because I don't know where to destroy them. Atleast, I think that's the problem.

Edited by WaveFunctionP
Link to comment
Share on other sites

I was actually looking at your code earlier. You are firing off your app initialization in the onGUIApplicationLauncherReady() method. (You do an check there for ApplicationLauncher.Ready.) So, I'm a bit confuzzled. I can copy that exact structure and it won't work for me, and unless I'm misunderstanding you (i probably am), then neither should yours.

I can put my button in Awake() and it works just fine. I get a button. However, I start getting duplicate buttons when switching vessels though because I don't know where to destroy them. Atleast, I think that's the problem.

Its the exact same function I used to use, but its called directly by awake now instead of via the event in my code. sorry should have linked this file too previously - https://github.com/TriggerAu/TransferWindowPlanner/blob/master/TransferWindowPlanner/TWP.cs#L68-69 . Line 69 is how I called it in 0.90, remmed out for line 68 in 1.0

You can see a bit further down in the OnDestroy code where I call the button destroy function - https://github.com/TriggerAu/TransferWindowPlanner/blob/master/TransferWindowPlanner/TWP.cs#L87. As the App Launcher now persists thats why we get the duplicate issue

Hope that makes sense

Link to comment
Share on other sites

Its the exact same function I used to use, but its called directly by awake now instead of via the event in my code. sorry should have linked this file too previously - https://github.com/TriggerAu/TransferWindowPlanner/blob/master/TransferWindowPlanner/TWP.cs#L68-69 . Line 69 is how I called it in 0.90, remmed out for line 68 in 1.0

You can see a bit further down in the OnDestroy code where I call the button destroy function - https://github.com/TriggerAu/TransferWindowPlanner/blob/master/TransferWindowPlanner/TWP.cs#L87. As the App Launcher now persists thats why we get the duplicate issue

Hope that makes sense

Yeah. The Awake and OnDestroy seems to work just fine now. I guess if you guys are doing that way, it's legit enough. :P

Now I just need to figure out why my icon isn't loading.

I tried to swap the texture

edit: Apparently one only need to use settexture on the button. That was easy enough. :)

Thanks for the help, guys. As usual, you guys are awesome!

Link to comment
Share on other sites

Contracts.ContractSystem.GetCurrentContracts()?

Idk, I just did a search in the references. There is no mention in the community docs from what I could see.

Thanks, for some reason Contracts.GetCurrentContracts() wasn't showing up as a method in MonoDevelop.

Link to comment
Share on other sites

How do I get a list of available contracts in a save?

Edit: Never mind. Are all contracts config based now?

They are sort of config based. If you want to create new contract your have to do C# code (or use Contract Configurator). Since Arsonide has taken over, all the stock contracts allow at least some some control/customization via config files.

And if you do still want the code, it is:

ContractSystem.Instance.GetCurrentContracts<TypeOfContract>() - but you'd have to call it for each and every type of contract (there's no way to get it all at once).

Link to comment
Share on other sites

They are sort of config based. If you want to create new contract your have to do C# code (or use Contract Configurator). Since Arsonide has taken over, all the stock contracts allow at least some some control/customization via config files.

And if you do still want the code, it is:

ContractSystem.Instance.GetCurrentContracts<TypeOfContract>() - but you'd have to call it for each and every type of contract (there's no way to get it all at once).

How do I get the type of contract?

Link to comment
Share on other sites

How do I get the type of contract?

You can use this function:

        public static IEnumerable<Type> GetAllTypes<T>()
{
// Get everything that extends the given type
List<Type> allTypes = new List<Type>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
IEnumerable<Type> types = null;
try
{
types = from type in assembly.GetTypes() where (type.IsSubclassOf(typeof(T)) || type.GetInterface(typeof(T).Name) != null) select type;
}
catch (Exception e)
{
Debug.LogException(new Exception("Error loading types from assembly " + assembly.FullName, e));
continue;
}

foreach (Type t in types)
{
Type foundType = t;

if (foundType != null)
{
yield return foundType;
}
}
}
}

Then call it as:

foreach (Type contractType in Something.GetAllTypes<Contract>())
{
...
}

Unless you have a contract object already, in which case its just:

theContract.GetType()

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