RockyTV Posted December 21, 2016 Share Posted December 21, 2016 Well, I don't think the issue is accessing Unity methods from constructors (we just don't access Time.realtimeSinceStartup from constructors). The only thing KSP complains about is about using Time.realtimeSinceStartup on a thread function (we spawn a thread and inside this thread's main function we call Time.realtimeSinceStartup). In case the source code helps, take a look: https://github.com/godarklight/DarkMultiPlayer/blob/b1bf1ef3d3850ffa33c624435ba0ee079f8aee73/Client/NetworkWorker.cs#L210-L307 Quote Link to comment Share on other sites More sharing options...
sarbian Posted December 21, 2016 Share Posted December 21, 2016 Constructor is the common case. Thread is the less used one. Still it should not be done. With MJ I had a bug that took me age to fix and was related to calling a Unity method from a thread. Quote Link to comment Share on other sites More sharing options...
kball Posted December 23, 2016 Share Posted December 23, 2016 Anyone know offhand if the resource/'Stage View' toggle is available as a GUIStyle? Quote Link to comment Share on other sites More sharing options...
ev0 Posted December 23, 2016 Share Posted December 23, 2016 On 12/13/2016 at 10:59 PM, nightingale said: @DMagic - looks like I inadvertently broke this will adding rounding in to fix another issue. I tried to be clever and round using the display format, which doesn't work with the P0 display format (because Float.Parse() doesn't have smarts to recognize a percentage). As a workaround, try using N1 + asPercentage. @nightingale @DMagic Could you give an example? I added "displayFormat = N2" and now have the following minus the toolTip: [GameParameters.CustomFloatParameterUI("Minimum Zoom", displayFormat = "N2", asPercentage = true, minValue = 0.05f, maxValue = 0.6f)] public float zoomMin = 0.35f; This lets me move the slider and adjust the ones place (35.00%, 36.00%, 37.00%), but displays two decimal points that I don't want. N1 shows only one decimal place but only lets me adjust the tens place (30.0%, 40.0%), and N0 doesn't let me adjust anything but has no decimals. Is there a way to adjust the ones place without displaying decimals anymore? Quote Link to comment Share on other sites More sharing options...
nightingale Posted December 23, 2016 Share Posted December 23, 2016 @ev0 - Ah, that's not a good workaround then. Okay, new plan - use a property: public float zoomMin = 0.35f; [GameParameters.CustomFloatParameterUI("Minimum Zoom (%)", displayFormat = "N0", asPercentage = false, minValue = 5f, maxValue = 60f)] public float zoomMinParam { get { return zoomMin * 100; } set { zoomMin = value / 100.0f; } } Downside of that approach is that the properties and fields will appear out of the order you expect (blame C#). Workaround for *that* would then be to make everything a property. Quote Link to comment Share on other sites More sharing options...
ev0 Posted December 24, 2016 Share Posted December 24, 2016 51 minutes ago, nightingale said: @ev0 - Ah, that's not a good workaround then. Okay, new plan - use a property: public float zoomMin = 0.35f; [GameParameters.CustomFloatParameterUI("Minimum Zoom (%)", displayFormat = "N0", asPercentage = false, minValue = 5f, maxValue = 60f)] public float zoomMinParam { get { return zoomMin * 100; } set { zoomMin = value / 100.0f; } } Downside of that approach is that the properties and fields will appear out of the order you expect (blame C#). Workaround for *that* would then be to make everything a property. That works, thanks. Wish I could have kept the percent sign after the number though Quote Link to comment Share on other sites More sharing options...
nightingale Posted December 24, 2016 Share Posted December 24, 2016 5 hours ago, ev0 said: That works, thanks. Wish I could have kept the percent sign after the number though You'll be able to change it back in the next™ release. Quote Link to comment Share on other sites More sharing options...
Tralfagar Posted January 4, 2017 Share Posted January 4, 2017 I believe KSP keeps a list of the possible Kerbal types (i.e. Pilot/Engineer/Scientist) within the vanilla game that is used to generate new Kerbals (such as by KerbalRoster.GetNewKerbal(Crew). Using mods that add in additional types (such as RoverDude's USI collection or maculator's Colonists! mod), it looks like KSP updates the record of the possible types when rolling random Kerbals. That is, types such as Geologist or Quartermaster appear in addition to Pilot and Engineer. Does anyone know where that information would be stored and how to access it? The KerbalRoster and HighLogic classes don't have anything that is obvious. Some background regarding my application: I want to be able to convert Kerbals from one occupation to another, but I'm not sure what mods someone may or not be using. For example, I want to change a Scientist to something else. In vanilla, the only options would be Pilot/Engineer. But if there are mods present, something like Geologist would be available, so Pilot/Engineer/Geologist. I think there are two approaches, but I'm not sure which is best: 1) Create a Module Manager plugin to add/subtract classes called in a module. This options seems like more overhead for me but is definitely doable with what I presently know. 2) Implement the logic to check the available Kerbal traits in C# so I don't need to explicitly know what traits are being used (I can delegate it to an iterative loop). This seems like the more "correct" solution, but I'm not sure if it's possible. Thank you! Quote Link to comment Share on other sites More sharing options...
rsparkyc Posted January 5, 2017 Share Posted January 5, 2017 Messing around with trying to update some mods. I see that the StrutConnector class is no longer present, but don't see anything in the docs about it's replacement. Any idea as to how to tell if a part is a strut connector? Quote Link to comment Share on other sites More sharing options...
Diazo Posted January 5, 2017 Share Posted January 5, 2017 Pretty sure that there is a dedicated partMoudule for that, it's CModuleStrut or something I think? D. Quote Link to comment Share on other sites More sharing options...
rsparkyc Posted January 5, 2017 Share Posted January 5, 2017 Just now, Diazo said: Pretty sure that there is a dedicated partMoudule for that, it's CModuleStrut or something I think? D. Ok, i saw that. The code I was looking at has if (part is StrutConnector) {...}, but it seems a part can never be a CModuleStrut. I'm just getting my feet wet in all this stuff, so I may need to do more digging to find out the difference between a Part and a PartModule Quote Link to comment Share on other sites More sharing options...
Diazo Posted January 5, 2017 Share Posted January 5, 2017 Currently a Part is the actual object in the game world takes care of the model, collisions, rendering on-screen, etc. Then that Part is assigned different PartModules depending on what functionality you want. There is no limit to the number of partModuls a part can have which is how you get multi-function parts. The (part is StrutConnector) you are referring to is the old system where there were only Parts, no partModules, so a Part could only be one thing. This was a crippling limitation and so has been replaced by the partModule system where a Part is a Part, functions are enabled by giving it partModules. D. Quote Link to comment Share on other sites More sharing options...
rsparkyc Posted January 5, 2017 Share Posted January 5, 2017 Ok, so I bet I can do something like this: if (part.FindModulesImplementing<CModuleStrut>().Count > 0) {...}. The old code was calling BreakJoint() on the StrutConnector, however I don't see anything like that on the part, nor the module. Perhaps we don't need to do that anymore? Quote Link to comment Share on other sites More sharing options...
DMagic Posted January 5, 2017 Share Posted January 5, 2017 Struts use a special kind of Part derivative: CompoundPart. And they use the PartModules found in the CompoundParts namespace, one of which is CModuleStrut. They are actually pretty easy to work with and have a nice method for terminating their connection: OnTargetLost(). Quote Link to comment Share on other sites More sharing options...
rsparkyc Posted January 6, 2017 Share Posted January 6, 2017 4 hours ago, DMagic said: Struts use a special kind of Part derivative: CompoundPart. And they use the PartModules found in the CompoundParts namespace, one of which is CModuleStrut. They are actually pretty easy to work with and have a nice method for terminating their connection: OnTargetLost(). I would think a method with the name OnTargetLost would be an event handler that would fire when the connection was terminated, and not actually cause the connection TO terminate. Quote Link to comment Share on other sites More sharing options...
Aghanim Posted January 7, 2017 Share Posted January 7, 2017 (edited) So I followed this thread to create my first KSP mod: and I use this Hello World code from that thread: using System; using UnityEngine; namespace HelloWorld { [KSPAddon(KSPAddon.Startup.Flight, false)] public class Hello : MonoBehaviour { public void Update() { Debug.Log("Hello world! " + Time.realtimeSinceStartup); } } } as MyClass.cs and compiled it using this Makefile: cmdlist = -t:library -lib:/home/feanor/Development/Programming/KSP_Modding/Managed -reference:Assembly-CSharp.dll -reference:Assembly-CSharp-firstpass.dll -reference:UnityEngine.dll -reference:UnityEngine.UI.dll dlllist = MyClass.dll cslist = MyClass.cs ksp_dir = "/home/feanor/Development/Programming/KSP_Modding/Kerbal Space Program" all: mcs $(cmdlist) $(cslist) clean: rm $(dlllist) install: cp $(dlllist) $(ksp_dir)/GameData run: $(ksp_dir)/KSP.x86_64 It successfully compiles the file, and KSP successfully loads the .dll file feanor@silmaril ~/.c/u/S/Kerbal Space Program> grep MyClass Player.log Load(Assembly): /MyClass AssemblyLoader: Loading assembly at /home/feanor/Development/Programming/KSP_Modding/Kerbal Space Program/GameData/MyClass.dll Non platform assembly: /home/feanor/Development/Programming/KSP_Modding/Kerbal Space Program/GameData/MyClass.dll (this message is harmless) MyClass v0.0.0.0 MyClass.dll According to the thread, this plugin should spam the debug log with Hello World! messages, but there is no message at all: What is wrong then with my setup? Edited January 7, 2017 by Aghanim Quote Link to comment Share on other sites More sharing options...
nightingale Posted January 7, 2017 Share Posted January 7, 2017 @Aghanim - This line: [KSPAddon(KSPAddon.Startup.Flight, false)] Means that your addon will be started in the flight scene. You'll see your log spam if you launch a vessel. Quote Link to comment Share on other sites More sharing options...
Aghanim Posted January 7, 2017 Share Posted January 7, 2017 (edited) @nightingale It works! So the guide is misleading, because it states this: Quote When you start KSP and reach the main menu, if everything is setup correctly, the code above will spam "Hello world!" to the console which is toggled on with Alt-F12. It will also append the time since the game was started so you can see the lines of text change. Edited January 7, 2017 by Aghanim Quote Link to comment Share on other sites More sharing options...
sarbian Posted January 7, 2017 Share Posted January 7, 2017 5 hours ago, Aghanim said: as MyClass.cs and compiled it using this Makefile: Be aware that this will compile as a .NET 4.5 lib. You should add "-sdk 2", "-nostdlib" and reference the mscorlib.dll shipped with KSP. Not sure how recent mono will deal with that... Quote Link to comment Share on other sites More sharing options...
JuhaJGamer Posted January 9, 2017 Share Posted January 9, 2017 Sorry if this has been asked before, how to add particle effects to modules in C# Quote Link to comment Share on other sites More sharing options...
blowfish Posted January 9, 2017 Share Posted January 9, 2017 2 hours ago, JuhaJGamer said: Sorry if this has been asked before, how to add particle effects to modules in C# If you have an effect defined in the part's EFFECTS node, you can cause it to play in a module by calling part.Effect(effectName, power) where effectName is the name of the effect in the EFFECTS node and power is a float from 0 to 1 indicating how strongly the effect should be played. Quote Link to comment Share on other sites More sharing options...
JuhaJGamer Posted January 9, 2017 Share Posted January 9, 2017 16 minutes ago, blowfish said: If you have an effect defined in the part's EFFECTS node, you can cause it to play in a module by calling part.Effect(effectName, power) where effectName is the name of the effect in the EFFECTS node and power is a float from 0 to 1 indicating how strongly the effect should be played. Thank you, I'm just starting. Also im trying to use ConfigNode but ksp just doesn't like it: System.IO.FileNotFoundException: Could not load file or assembly 'KSPUtil, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. File name: 'KSPUtil, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Quote Link to comment Share on other sites More sharing options...
blowfish Posted January 9, 2017 Share Posted January 9, 2017 1 minute ago, JuhaJGamer said: Thank you, I'm just starting. Also im trying to use ConfigNode but ksp just doesn't like it: System.IO.FileNotFoundException: Could not load file or assembly 'KSPUtil, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. File name: 'KSPUtil, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Remove the reference to KSPUtil. Everything that was in that DLL was moved back into Assembly-CSharp. Quote Link to comment Share on other sites More sharing options...
JuhaJGamer Posted January 9, 2017 Share Posted January 9, 2017 2 minutes ago, blowfish said: Remove the reference to KSPUtil. Everything that was in that DLL was moved back into Assembly-CSharp. Thanks! I dont know why Visual Studio tried to forcefully have KSPUtil refrenced Quote Link to comment Share on other sites More sharing options...
JuhaJGamer Posted January 9, 2017 Share Posted January 9, 2017 (edited) Has anyone got any idea of how to make a vessel rendezvous with another vessel, and then set the velocity relative to the target at ~50m/s. Rendezvous in kind of like the in-game cheat rendezvous which sets the vessel 150m away from the target. Edited January 9, 2017 by JuhaJGamer 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.