-
Posts
2,077 -
Joined
-
Last visited
Content Type
Profiles
Forums
Developer Articles
KSP2 Release Notes
Everything posted by Diazo
-
The Lifecycle of a Part Module - A Primer
Diazo replied to blowfish's topic in KSP1 C# Plugin Development Help and Support
I will caution that this needs testing, I've run into inconsistent behavior where sometimes Load runs then Start, and sometimes Start runs then Load depending on which mode (Editor/Flight) you are in. This may have been on a KSPAddon instead of a PartModule also, but as they are so similar it is something to be aware of. D.- 22 replies
-
- part modules
- information
-
(and 1 more)
Tagged with:
-
Assuming that you are working with a Vessel (such as FlightGlobals.ActiveVessel), you have to cycle every part and check the Part.Actions enum, then cycle every PartModule.Actions on that part to see what you are looking for. If you don't care about which actiongroup and are just checking if one is assigned, you can do a != KSPactionGroup.None check, but otherwise you have to do bitwise math. Note that I've never seen an action assigned in the Part.Actions enum and assume it is old code replaced by the PartModule.Actions enum, but I still check it to be safe. I make a list of all actions on a vessel here: https://github.com/SirDiazo/AGExt/blob/master/AGExt/Editor.cs#L3135 Then I check that list against a specific action type (Brakes/Lights/etc.) here: https://github.com/SirDiazo/AGExt/blob/master/AGExt/Editor.cs#L3170 Hope that helps, D.
-
[1.3](Jun04/17) Automate Vertical Velocity and Altitude Control
Diazo replied to Diazo's topic in KSP1 Mod Releases
@Deimos Rast After trying to bind the key, the settings screen actually displays (Key:55665) in the top line? That is really weird, the way the key code enum works it should always display the human readable name of the key, not the key code. As a workaround you can set the key in the TWR1.settings file in the mod folder using the keycodes found here: https://docs.unity3d.com/ScriptReference/KeyCode.html I'll have to look into what that number means (if you could confirm the exact number, that would help), the code I'm using should always return a valid key on the keyboard or a joystick button, so I'm not sure how a random number got in there. D. -
@genericeventhandler The issue that I'm using that code to reference singeltons in the stock KSP code which I can't make changes to so I work around this issue with the try/catch block. It works and I know of no better solution, and I've bounced this question off the forum and #KSPModders before (although months, maybe over a year, ago) and no one else had any ideas either. D.
-
Unfortunately, there are several quirks present relative to exceptions that I'm not sure whether to blame on KSP or Unity that muddy this situation. I don't think I am guilty of exactly anything you are posting here, but I do use some logic that is awfully close for reasons as follows: 1) KSP uses singletons quite a bit so I have not found any other way to handle something like this: public class Master { public static Master ourMaster public string ourText } //If ourMaster is not initialized yet... public void Update() { if(ourMaster != null) //returns true { if(ourMaster.ourText != null) //this throws a NullRef error instead of returning false, need a try/catch block to handle it } } 2) KSP uses sequential routines a lot, for example the load routine: public class ourPartModule : PartModule { public ConfigNode Load(ConfigNode node) { //stick any code here that throws a nullref error } } This nullref error causes the entire load routine to abort. Ran into this several months ago where only the root part would spawn as the load routine starts there, ksp would spawn the part and while trying to load the partModules on it run into this nullref error and KSP just threw its hands up and stopped the entire load routine leaving you with a single part visible in the editor. Again, the only way I've ever found to handle this is a try/catch block so you keep the error contained within your own code, but I use the existing exceptions for that so I don't think it's exactly the same issue. D.
-
My answer is conditional on the resource system not having changed in the past few versions, but as far as I know this still works. How resources on a part respond to resource requests is controlled by the mode that resource is set to. There is a global setting for that resource, but there is also a local override on a per part basis. Part.Resources is a list of PartResource objects, of which you can set the flow mode for that resource for this part specifically, including electricity. Note that this is specific to resources on this part only, resource requests across this part are affected by the Part.Crossfeed value. To stop a part from allowing it's resources to be consumed, set the PartResource.FlowMode to none, to cause a part to block resource requests from parts attached to one side from parts on the other side, set Part.Crossfeed false. Hope that helps, D.
-
How do I get the friendly name of a part?
Diazo replied to nadseh's topic in KSP1 C# Plugin Development Help and Support
There is actually a PartInfo class that is a property of the Part class that has all the part UI information like that name. You'll have to drill down into that and find the in-game display name in there. (I might have that class name wrong, it might be slightly off as I'm going from memory.) D. -
@KoolBreeze420 That is the error AGX throws when it thinks you have RemoteTech installed but do not have control of the craft. 1) Do you have RemoteTech installed? 2) Does RemoteTech show you as having control of the craft? (Set throttle, change orientation, etc.) As a work around, you can right click on the AGX icon and select the "Bypass RT" option and AGX will not check RT and execute the action group anyway. D.
- 1,353 replies
-
- edit actions
- actions
-
(and 1 more)
Tagged with:
-
@baldamundo I have not forgotten about that, but real life is slamming me right now and I haven't even been able to turn my KSP desktop on for the last 5 weeks, let alone look at modding. I do want to get to that, but no clue on a timeline. @Redneck For timing delays I point people towards Smart Parts. It recognizes all action groups available so if AGX is installed it can activate any of the 250 action groups. D.
- 1,353 replies
-
- 1
-
-
- edit actions
- actions
-
(and 1 more)
Tagged with:
-
Your logic is right in that FindModuleImplementing<> only returns the first module of that type. It's a pretty simple fix though: public class AYA_Science : PartModule { [KSPEvent(guiActive = true, guiActiveEditor = false, guiName = "Perform All Science")] public void DoAllScience() { foreach (Part eachPart in vessel.Parts) //cycle through all parts { foreach (PartModule pm in eachPart.modules) //cycle through all partModules on the current part { if(pm is ModuleScienceExperiment) //check if current partModule is a ModuleScienceExperiment, or inherited from one. 'is' is a C# keyword for this. { (ModuleScienceExperimet)pm.DeployExpriment(); //since the current partModule is a ModuleScienceExperiment, cast from type PartModule to type ModuleScienceExperiment so we can call .DeployExperiment. { } } } } There is probably ways using the shortcut methods Squad supplies for working with modules that would accomplish this in fewer lines of code, but this makes it clear what is going on. On the error you don't understand in your second post, I'm pretty sure all you need to do is add a second set of empty brackets at the end of the line. D.
-
My suspicion is that the new/base is not behaving as you expect. If you add a Debug.Log(base.GetType()); line just before your base.DeployExperiment() line, what type does KSP think the 'base' class is? (It should print either SolarExperiment or ModuleScienceExperiment). The second check is to go into your part.cfg file and change the SOLAREXPERIMENT line to MODULESCIENCEEXPERIMENT and make sure everything else woks to isolate the issue as actually being where you think it is. D.
-
It works fine in a quick 5 minute test. All of my mods work fine actually and nothing in the patch notes affects what I interface with so the most recent version of all my mods should work on 1.1.3. (AutoActions is the exception, you'll need to grab a community fix from the last page of it's thread until I can find some time to officially update it.) D.
-
I was not able to find this myself either when I looked for it. If there is something, it's probably going to be something in the underlying Unity stuff, rather then the KSP stuff. The one method I did find was the .closestPointOnBounds method which I was able to finagle for my purposes, but I'm not sure how you'd go about using that to get vessel length. D.
-
Okay, this is getting rather heated. @Stone Blue I was peripherally involved in the discussion when ferram made his original request to have FAR delisted and it generated pages and pages of discussion at the time. The short answer is that the CKAN staff were able to make a logical case for why they would have a policy of not de-listing mods, it's not a case of them being flat out wrong. How strong their case is and whether you agree or disagree with that policy is going to be personal opinion. However, that means this discussion has already been had. I can link the previous discussion if you want to read the positions for yourself, but otherwise I think the question posed at the start of this thread has been answered and would ask that this be dropped before people already entrenched in their position from the previous discussion use this thread to start yelling at each other about it. D.
-
Overall, I personally see CKAN as a good thing, but it's not overwhelmingly so. As a mod author who's been hit with a lot of these issues, CKAN's issues mostly boil down to the fact that it's too open. It's all good to open the CKAN up to allow anyone to add a mod to it as that gets more mods (and so faster adoption of CKAN) to happen, but it also means people who don't know what they are doing start messing around things break in very short order. 3 times I've had people "help" by going to CKAN and updating my mods but breaking them instead. This is the biggest strike against CKAN, as a mod author I can't control my mods on it, all I can do is keep an eye on it and revert any breaking changes made as soon as I notice them. The other strike against CKAN is that there is no dependency control with other mods. While it does a good job of checking which version of a mod work on a specific KSP version, there is no way for a mod author to say "I need this version of this other mod for my mod to work". CKAN just always installs the latest version of a mod. I'm pretty sure this is why FAR and CKAN have had so many issues playing nice with one another (or at least one of the reasons). On the plus side, it does work most of the time and makes installing/uninstalling mods so much easier for the average player. As such it does make for a better game experience so I do consider CKAN's positives to outweigh the negatives. D.
-
Vertical Velocity - how to VTOL
Diazo replied to genericeventhandler's topic in KSP1 Mods Discussions
Vertical Velocity Control asked you to remap keys to work? It shouldn't do that, there is an option to bind a single key if you want to use it for keyboard control, but I think most people use mouse control with it these days. It should also hook into Davon's Throttle Control with the specific purpose of making the vertical <-> horizontal flight transition easier. (Control by action group is also possible if you also install ModActions, but I don't think that control method's had a lot of interest.) D. -
@DennyTX That is what I ended up doing. The answer to my question in the first post is that Unity only calls OnGUI() in classes that inherit from monobehavior, so you either have to tag your class as a monobehavior (which I can't in this specific case), or call your own GUI method via a call in a OnGUI of a monobehavior class such as the KSPAddon.Flight class for your mod as per your code snippet. D.
-
With the warning that I've never actually used it, have you looked at the ModuleAnimateGroup that's in stock? From discussion way back when, this was added with the intent of handling parts with multiple animations on them. D.
- 16 replies
-
- kspfield
- kspapiextensions
-
(and 1 more)
Tagged with:
-
Loading/Writing to config files
Diazo replied to a topic in KSP1 C# Plugin Development Help and Support
static is a C# keyword meaning that only one instance of that class can exist. https://msdn.microsoft.com/en-CA/library/79b3xss3.aspx In this case it's being used so other classes can call the LoadSettings method without having to get a reference to the Settings class instance first. D. -
Hmm, I would argue that ModuleFuelTanks.cs is not "adding" an event, it's making a new event every time the part loads, so it's a different event each time. I realize I am being nitpicky about this, but there is an important difference between the two. Adding an event: For an event to qualify as being added, KSP would take over once it had been added and it would be added to the save/load. That means once you'd run your AddEvent code once, the event would be present on that part from then on, even across save/loads. (I required this for my purposes which is why I dropped it.) Tagging a method with KSPEvent in Visual Studio qualifies for this definition. Recreating the event: This method requires the event to be recreated every time the part loads, you have to take care of save/loading data, making sure the event shows/hides when needed, etc. Depending on your use-case this might work for you I guess. This is what ModularFuelTanks.cs is using. The lack of persistence is the big difference, one of the primary purposes of the KSPField is to provide easy persistence for mods and you won't have that without writing your own save/load code yourself. D.
- 16 replies
-
- 1
-
-
- kspfield
- kspapiextensions
-
(and 1 more)
Tagged with:
-
Short answer is no, you can't add KSPFields (or KSPActions/KSPEvents) at runtime. Long answer is that it looks like even though KSP creates an instance of a part to make the ProtoParts database, it still makes a new instance of all the objects on the part when the part is created in the 3D gamespace. I do have to preface this that I was trying to do this with a KSPAction, not a KSPField, and it was back in KSP 0.25, but I have no reason to think Squad's changed how spawning of parts works. I was able to create a KSP action at runtime and add it to a part in the 3D gamespace. I was also able to add the action to a ProtoPart in the ProtoParts database. However, nothing I did was able to make that action I added to the ProtoPart stay in existence when said part was placed in the 3D gamespace which made it useless for my purposes so I stopped experimenting there. That means I never investigated if a dynamically added KSPAction would persist through a save/load cycle. The action not being present after the ProtoPart -> 3D gamespace transition is also where my conclusion that this process does not copy the ProtoPart, rather it spawns new instances of all the code objects attached to the ProtoPart and reads the data in fresh from the part.cfg values (including the ModuleManager modifications). The best workaround I found was to make empty "template" KSPActions that I could then change the properties of dynamically at run time. D.
- 16 replies
-
- kspfield
- kspapiextensions
-
(and 1 more)
Tagged with:
-
If the file is missing, it will be created the next time KSP is run. (You have to actually go into a game, just the Main Menu is not far enough. Into the Editor or Flight mode preferred.) If you have actually played and the file is not present, that is a bug I'll have to look into. D.
- 1,353 replies
-
- edit actions
- actions
-
(and 1 more)
Tagged with:
-
Yes, that is how overiding works, the FixedUpdate in the sub-class runs in place of the FixedUpdate in the parent class. You can make use of the BASE modifier however, if you stick "base.FixedUpdate()" on a line in the sub-class, it will run the FixedUpdate in the parent class at that point, then finish off running the FixedUpdate() in the sub-class. public class CivilianSpawnGrowth: CivilianDockGrowth { public override void OnFixedUpdate () { Debug.Log (debuggingClass.modName + "CivilianSpawnGrowth checking in!"); base.OnFixedUpdate(); //as so } } D.