johnqevil Posted April 8, 2015 Share Posted April 8, 2015 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! Quote Link to comment Share on other sites More sharing options...
Fanatorium Posted April 11, 2015 Share Posted April 11, 2015 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 Quote Link to comment Share on other sites More sharing options...
_selfishPerson Posted April 13, 2015 Share Posted April 13, 2015 Hello!I'm just wondering if anyone here knows which event is called when you click the buttons on the GUI at the top of the screen when flying?Thanks! Quote Link to comment Share on other sites More sharing options...
Diazo Posted April 13, 2015 Share Posted April 13, 2015 @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. Quote Link to comment Share on other sites More sharing options...
_selfishPerson Posted April 13, 2015 Share Posted April 13, 2015 @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! Quote Link to comment Share on other sites More sharing options...
_selfishPerson Posted April 14, 2015 Share Posted April 14, 2015 Does anyone know what the queueSpot argument does in AddToPostDrawQueue? Or can I just put random values in and I will be fine? Quote Link to comment Share on other sites More sharing options...
sarbian Posted April 14, 2015 Share Posted April 14, 2015 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 ? Quote Link to comment Share on other sites More sharing options...
Warzouz Posted April 14, 2015 Share Posted April 14, 2015 I have 2 questions- Is it possible to develop using VisualBasic .Net instead ofVisual C# .Net ? (I think yes, but...)- Is there some where as description of the save files format ? Quote Link to comment Share on other sites More sharing options...
sarbian Posted April 14, 2015 Share Posted April 14, 2015 It is, but you won't get much help here if you use VBNo. 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. Quote Link to comment Share on other sites More sharing options...
_selfishPerson Posted April 14, 2015 Share Posted April 14, 2015 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 Quote Link to comment Share on other sites More sharing options...
Crzyrndm Posted April 14, 2015 Share Posted April 14, 2015 (edited) 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 April 14, 2015 by Crzyrndm Quote Link to comment Share on other sites More sharing options...
_selfishPerson Posted April 14, 2015 Share Posted April 14, 2015 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 queueOh right! I see. It's a very simple mod so I think I'll stick to it but thanks for the tip! Quote Link to comment Share on other sites More sharing options...
Fanatorium Posted April 16, 2015 Share Posted April 16, 2015 @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 Quote Link to comment Share on other sites More sharing options...
WaveFunctionP Posted April 28, 2015 Share Posted April 28, 2015 (edited) 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 April 28, 2015 by WaveFunctionP Quote Link to comment Share on other sites More sharing options...
xEvilReeperx Posted April 29, 2015 Share Posted April 29, 2015 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} Quote Link to comment Share on other sites More sharing options...
TriggerAu Posted April 29, 2015 Share Posted April 29, 2015 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 menuThats 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 Quote Link to comment Share on other sites More sharing options...
WaveFunctionP Posted April 29, 2015 Share Posted April 29, 2015 (edited) 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 menuThats 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.csI 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 April 29, 2015 by WaveFunctionP Quote Link to comment Share on other sites More sharing options...
TriggerAu Posted April 29, 2015 Share Posted April 29, 2015 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.0You 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 issueHope that makes sense Quote Link to comment Share on other sites More sharing options...
WaveFunctionP Posted April 29, 2015 Share Posted April 29, 2015 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.0You 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 issueHope that makes senseYeah. The Awake and OnDestroy seems to work just fine now. I guess if you guys are doing that way, it's legit enough. Now I just need to figure out why my icon isn't loading.I tried to swap the textureedit: 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! Quote Link to comment Share on other sites More sharing options...
Robotengineer Posted April 29, 2015 Share Posted April 29, 2015 (edited) How do I get a list of available contracts in a save?Edit: Never mind. Are all contracts config based now? Edited April 29, 2015 by Robotengineer Quote Link to comment Share on other sites More sharing options...
WaveFunctionP Posted April 29, 2015 Share Posted April 29, 2015 How do I get a list of available contracts in a save?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. Quote Link to comment Share on other sites More sharing options...
Robotengineer Posted April 29, 2015 Share Posted April 29, 2015 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. Quote Link to comment Share on other sites More sharing options...
nightingale Posted April 29, 2015 Share Posted April 29, 2015 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). Quote Link to comment Share on other sites More sharing options...
Robotengineer Posted April 29, 2015 Share Posted April 29, 2015 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? Quote Link to comment Share on other sites More sharing options...
nightingale Posted April 29, 2015 Share Posted April 29, 2015 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() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.