Superfluous J Posted April 5, 2016 Share Posted April 5, 2016 (edited) About 3 hours ago, I decided that an idea I had was simple enough, that even I could mod it. 3 hours later, I've successfully followed the steps in the tutorial in the wiki and gotten a fake RCS block to log "Hello, Kerbin!" to the log file when I add it to my craft. I kinda get how it works, but am by no means confident enough to do much more than change the text string that is logged. In looking through the modder forum, I see a 3-year-old topic with 5 tutorials from the guy who did TAC fuel balancer, and I can't help but think maybe they're a bit outdated. I'll still look though them, but I'm a bit scared considering I don't really see any other tutorials out there and - frankly - I'm feeling a bit like a fish that was taken out of water and put in an Advanced Calculus class, and then was expected to be the teacher's assistant. I quite literally have no idea what is going on or how to even ask questions. Are there better (or at least newer) tutorials out there? Are the TAC tutorials still valid? Are there some really well documented mods that anybody could suggest I look at (the simpler the better). What I do NOT want is someone to write this for me. I'd rather do without than have that. To keep up with the fish analogy I want to learn to fish, not get a free fish Edited April 5, 2016 by 5thHorseman Link to comment Share on other sites More sharing options...
Stone Blue Posted April 5, 2016 Share Posted April 5, 2016 How bout more detail on what you're trying to do?... Make just simple parts? Make just a plugin? Make parts with functions that also need a pluDo you need modelling/texture help write now? or coding help? If modelling/texturing, Beale has a GREAT write-up for Wings3D... I used it (and Wings3D) to make MY first part... Link to comment Share on other sites More sharing options...
Superfluous J Posted April 5, 2016 Author Share Posted April 5, 2016 17 minutes ago, Stone Blue said: How bout more detail on what you're trying to do?... Make just simple parts? Make just a plugin? Make parts with functions that also need a pluDo you need modelling/texture help write now? or coding help? If modelling/texturing, Beale has a GREAT write-up for Wings3D... I used it (and Wings3D) to make MY first part... I don't want to make a part. I want to modify the right-click menus for parts. Kind of like how GPOSpeed Fuel Pumps modifies the right-click menu of fuel tanks. Specifically, what I want to do (to start) is to modify all deployable solar panels so that they gain a 2 menu options "Deploy all solar panels" and "retract all solar panels." Eventually, I'd like to extend it so - via a config file - you could add similar things to any parts you want, including perhaps command modules. Imagine right-clicking a command pod and having "deploy all solar panels" there. Link to comment Share on other sites More sharing options...
NathanKell Posted April 5, 2016 Share Posted April 5, 2016 The TAC stuff should still be correct, PartModules haven't changed enough, and that'll still even work in 1.1 although you might need to reference more KSP dlls (KSPUtil and KSPCore, say). Making that menu should be fairly straightforward. You'd make a partmodule (and use ModuleManager to add it to all parts that have the solar panel module). The module would have a KSPEvent (active only in flight?) that loops through all parts on the vessel, and all modules on each part, and if it's a solar panel, calls the deploy method in the panel. Link to comment Share on other sites More sharing options...
Crzyrndm Posted April 5, 2016 Share Posted April 5, 2016 1 hour ago, NathanKell said: The TAC stuff should still be correct, PartModules haven't changed enough, and that'll still even work in 1.1 although you might need to reference more KSP dlls (KSPUtil and KSPCore, say). Making that menu should be fairly straightforward. You'd make a partmodule (and use ModuleManager to add it to all parts that have the solar panel module). The module would have a KSPEvent (active only in flight?) that loops through all parts on the vessel, and all modules on each part, and if it's a solar panel, calls the deploy method in the panel. To add some code examples: // inheriting from partModule public class SolarSwitch : PartModule { [KSPEvent (/* fill in params here to give it a UI name, select when it's active (flight/editor), etc. */)] public void OpenAll() { // outer loop is over vessel.parts to get each part on the vessel // inner loop is over p.Modules where p is the part selected in the outer loop // ModuleDeployableSolarPanel is the type you're looking for and it has functions "Extend" and "Retract" } } Link to comment Share on other sites More sharing options...
Superfluous J Posted April 5, 2016 Author Share Posted April 5, 2016 5 hours ago, NathanKell said: Making that menu should be fairly straightforward. You'd make a partmodule (and use ModuleManager to add it to all parts that have the solar panel module). The module would have a KSPEvent (active only in flight?) that loops through all parts on the vessel, and all modules on each part, and if it's a solar panel, calls the deploy method in the panel. That's the pseudocode in my head It's all the fiddly bits that are getting me. I'm hoping after a solid day's sleep I'll be more in tune with my inner coder tonight. Link to comment Share on other sites More sharing options...
DMagic Posted April 5, 2016 Share Posted April 5, 2016 Actually, I think Vessel has a FIndPartModules method. I'm not sure if it's any faster than making the loop yourself (it probably does the same thing), but it should give you a list of all the ModuleDeployableSolarPanels in the vessel. Then you would just need to update the list whenever the vessel is modified. Then just run through each element of the list and call the deploy or retract method. Link to comment Share on other sites More sharing options...
Superfluous J Posted April 6, 2016 Author Share Posted April 6, 2016 (edited) 6 hours ago, Crzyrndm said: // ModuleDeployableSolarPanel is the type you're looking for and it has functions "Extend" and "Retract" 2 hours ago, DMagic said: Then just run through each element of the list and call the deploy or retract method. How would I call these methods? I tried using Extend and Retract and am being told there are no such methods. Here's my code that fails to compile ("Extend" fails as well): foreach (Part eachPart in vessel.Parts) { if (eachPart.Modules.Contains("ModuleDeployableSolarPanel")) { eachPart.Retract(); } } And here's the error VS is giving me: Error CS1061 'Part' does not contain a definition for 'Retract' and no extension method 'Retract' accepting a first argument of type 'Part' could be found (are you missing a using directive or an assembly reference?) And of course, more than knowing what the methods are named, I'm more interested in how I'd find out myself UPDATE: I got the code to compile by modifying the above to the below. I've also got buttons in flight now, but they don't do anything. Baby steps. foreach (Part eachPart in vessel.Parts) { if (eachPart.Modules.Contains("ModuleDeployableSolarPanel")) { eachPart.SendEvent("Retract"); } } Edited April 6, 2016 by 5thHorseman Link to comment Share on other sites More sharing options...
Aelfhe1m Posted April 6, 2016 Share Posted April 6, 2016 You need to reference the module within the part: foreach (Part eachPart in vessel.Parts) { if (eachPart.Modules.Contains("ModuleDeployableSolarPanel")) { var panel = eachPart.FindModuleImplementing<ModuleDeployableSolarPanel>(); panel.Retract(); } } Link to comment Share on other sites More sharing options...
NathanKell Posted April 6, 2016 Share Posted April 6, 2016 or even just foreach(Part p in vessel.Parts) { var panel = p.FindModuleImplementing<ModuleDeployableSolarPanel>(); if(panel != null) panel.Retract(); } that means you only search the modules once per part. Link to comment Share on other sites More sharing options...
Superfluous J Posted April 6, 2016 Author Share Posted April 6, 2016 8 minutes ago, Aelfhe1m said: You need to reference the module within the part: foreach (Part eachPart in vessel.Parts) { if (eachPart.Modules.Contains("ModuleDeployableSolarPanel")) { var panel = eachPart.FindModuleImplementing<ModuleDeployableSolarPanel>(); panel.Retract(); } } That worked! Thank you. I have no idea how I'd have ever gotten that on my own, but I at least understand the syntax. Link to comment Share on other sites More sharing options...
NathanKell Posted April 6, 2016 Share Posted April 6, 2016 Let's go through it then: 1. You're iterating over all parts in the vessel. 2. Given a part, you then see if its list of PartModules contains a partmodule named ModuleDeployableSolarPanel (note: this method is not safe, better method is what I proposed*) 3. If the part does have such a module, get it by finding the first module in the part of type ModuleDeployableSolarPanel 4. Finally, call that panel's method. *This is not safe because, as my description above hopefully showed, the code is doing two different things. First it's finding if the part has a module that explicitly is (i.e. its type matches the string) ModuleDeployableSolarPanel. Next, however, you are finding a PartModule that is or is derived from that type. Since presumably you want to handle panels on modules that are derived, not just are, it's better to use the type form rather than the string form. However, it's even better to do a foreach(ModuleDeployableSolarPanel pan in eachPart.FindModulesImplementing<ModuleDeployableSolarPanel>().ToList()) and then pan.Retract() The reason for that is it will do it to all partmodules of (or derived from) that type on the part, not just the first. And the reason for the ToList() is that otherwise it will re-run that Find... method each time the foreach executes (IIRC) rather than only once. Link to comment Share on other sites More sharing options...
Superfluous J Posted April 6, 2016 Author Share Posted April 6, 2016 18 minutes ago, NathanKell said: *This is not safe because, as my description above hopefully showed, the code is doing two different things. First it's finding if the part has a module that explicitly is (i.e. its type matches the string) ModuleDeployableSolarPanel. Next, however, you are finding a PartModule that is or is derived from that type. Since presumably you want to handle panels on modules that are derived, not just are, it's better to use the type form rather than the string form. However, it's even better to do a foreach(ModuleDeployableSolarPanel pan in eachPart.FindModulesImplementing<ModuleDeployableSolarPanel>().ToList()) and then pan.Retract() Nice. I see this. I'll modify the solar panels when I go back in and add radiators for the next version. I somehow missed your last post, I think maybe we both posted in quick succession. Link to comment Share on other sites More sharing options...
tg626 Posted April 6, 2016 Share Posted April 6, 2016 Hang in there! I can't tell you how many hours (and how much hair) I lost just trying to get my docking port sound mod to work!! Link to comment Share on other sites More sharing options...
Padishar Posted April 6, 2016 Share Posted April 6, 2016 (edited) The original suggestions mentioned looping through the PartModules and doing the action for each ModuleDeployableSolarPanel found. If it is possible to have more than one per part then this should definitely be done or some parts will only deploy one of their sub-panels (e.g. I suspect some of the Near Future panels might have multiple if it's possible). Ahhh, on a more in-depth reading, I see Nathan has already mentioned that... Edited April 6, 2016 by Padishar Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now