Jump to content

change part config.


Recommended Posts

To make a function on a PartModule be callable via action groups, you want the "KSPAction" annotation.   Here's an example.

I'm not totally sure whether "max temperature" on a part is something that you can set in flight, or whether it's baked in at config load time (since I've never actually tried it), but it's a simple thing to test.  :) 

The tricky bit is this:

14 minutes ago, MrMcMuffinJr said:

all parts on an active vessel

...The way that action groups work is that  they function on PartModules on individual parts.  They generally don't work on a vessel.

So, it seems to me that your task would look something like this:

  1. Create yourself a PartModule that does what you want.  It would have a method on it annotated with KSPAction for doing the temperature toggle.  What the method does is to set the max temp on the part.  (You'll need to pay attention to two separate max temperatures:  the "main" one, and the "skin" one.)
  2. Put your PartModule on every single part in the game, probably with some ModuleManager config (which means you'll likely want to bundle ModuleManager with your mod).

...The question, though, then becomes "how does your action on all these parts then become actually associated with a particular action group"?  You have a few choices, none of them super pretty:

  • Option 1:  Take no special action in your code.  For your "toggle temperature" option to be available, the user will have to click on every individual part in the vehicle editor and manually add it to the action group of the player's choice.  This is ugly because it'll be tedious and error-prone every single time the player builds a new ship.
  • Option 2:  In the code for your custom PartModule, specify a default action group for it to be in.  This saves all the player tedium... but it has a different ugliness, which is that now it's hard-coded which action group it is.  If you pick, say, Custom01 for the action group that it always adds to, then you'll annoy any player that doesn't want it to be that group.  They can manually reassign, but it'll be really tedious.
  • Option 3 (could be combined with either of the above):  You could write a bunch of code in your mod so that when a player adjusts the action group assignment for one part in the vehicle editor, it automatically propagates to all parts in the whole ship.  This is ugly because, 1. you have to write a bunch more code, and 2. it may not be expected by the user (it's not the usual behavior of action group assignments).

And of course all of the above options will have the ugliness that they seriously clutter up the action group pane.  If you've got 100 parts on your ship and they all individually have this action group hooked up, it means that when you go to the action group menu, you'll see all 100 of them bloating the menu.  Not sure how much you care about that.

Anyway, just my two cents.  It's not pretty.  Maybe someone more knowledgeable than me might have a better idea for a less-ugly solution (if one exists), but that's about the best I can think of off the top of my head.

Link to comment
Share on other sites

5 minutes ago, Snark said:

To make a function on a PartModule be callable via action groups, you want the "KSPAction" annotation.   Here's an example.

I'm not totally sure whether "max temperature" on a part is something that you can set in flight, or whether it's baked in at config load time (since I've never actually tried it), but it's a simple thing to test.  :) 

The tricky bit is this:

...The way that action groups work is that  they function on PartModules on individual parts.  They generally don't work on a vessel.

So, it seems to me that your task would look something like this:

  1. Create yourself a PartModule that does what you want.  It would have a method on it annotated with KSPAction for doing the temperature toggle.  What the method does is to set the max temp on the part.  (You'll need to pay attention to two separate max temperatures:  the "main" one, and the "skin" one.)
  2. Put your PartModule on every single part in the game, probably with some ModuleManager config (which means you'll likely want to bundle ModuleManager with your mod).

...The question, though, then becomes "how does your action on all these parts then become actually associated with a particular action group"?  You have a few choices, none of them super pretty:

  • Option 1:  Take no special action in your code.  For your "toggle temperature" option to be available, the user will have to click on every individual part in the vehicle editor and manually add it to the action group of the player's choice.  This is ugly because it'll be tedious and error-prone every single time the player builds a new ship.
  • Option 2:  In the code for your custom PartModule, specify a default action group for it to be in.  This saves all the player tedium... but it has a different ugliness, which is that now it's hard-coded which action group it is.  If you pick, say, Custom01 for the action group that it always adds to, then you'll annoy any player that doesn't want it to be that group.  They can manually reassign, but it'll be really tedious.
  • Option 3 (could be combined with either of the above):  You could write a bunch of code in your mod so that when a player adjusts the action group assignment for one part in the vehicle editor, it automatically propagates to all parts in the whole ship.  This is ugly because, 1. you have to write a bunch more code, and 2. it may not be expected by the user (it's not the usual behavior of action group assignments).

And of course all of the above options will have the ugliness that they seriously clutter up the action group pane.  If you've got 100 parts on your ship and they all individually have this action group hooked up, it means that when you go to the action group menu, you'll see all 100 of them bloating the menu.  Not sure how much you care about that.

Anyway, just my two cents.  It's not pretty.  Maybe someone more knowledgeable than me might have a better idea for a less-ugly solution (if one exists), but that's about the best I can think of off the top of my head.

I believe I worded it wrong. I intend to make one custom part have an action group. that single action group will toggle different heat tolerance values for all parts on the active vessel.

Edited by MrMcMuffinJr
Link to comment
Share on other sites

48 minutes ago, MrMcMuffinJr said:

I believe I worded it wrong. I intend to make one custom part have an action group. that single action group will toggle different heat tolerance values for all parts on the active vessel.

Ah, okay.  That simplifies matters.

  1. You'll make a custom PartModule, which you put on your part.
  2. It will have a method on it which you decorate with the KSPAction annotation, so that it'll be available via action group.
  3. You'll probably also want something decorated with KSPEvent annotation, so that it'll also be available via the part's right-click menu.
  4. I'll assume you'll want the numbers that control your behavior to be something that comes from your part config, and not hard-coded into the module.  So in that case, you'll also want to decorate that with the KSPField annotation.
  5. In the code that you execute when someone triggers the menu item or action group, you'll iterate through every part on the vessel and adjust its max temperature settings.
  6. When you create your part, your part config will be set up to put your PartModule on it, and to set whatever config values you want for the PartModule.

Of the above items advice, #5 is the only one I'm not totally sure about.  The thing I'm not sure about is whether the game will actually let you change the max temperature of individual parts on a vessel, in flight.  I don't know that you can't... but I don't know that you can, either.  It's something you'd have to experiment with to verify that it's possible.

Another complication that I expect you'll likely need to write code to handle, assuming that setting the max temps actually is possible:  Let's say that there are two possible states.  "Triggered" (when you have the thing turned on, so it's tweaking the max temps) and "untriggered" (when it's turned off and they have their default temperatures).  Suppose you're in the triggered state, and then you exit the game or switch away from that vessel.  I'm pretty sure that the per-part max temps aren't saved with the ship in your .sfs file.  So when you switch back to that ship, all your customized temperature settings will (I think) be gone.  If that's the case, then you'd need to run some additional code in your custom PartModule that runs when it loads up, so that it checks whether the action group is active or not; and if it is, does the iterate-over-everything-and-set-temperatures thing again.

 

Link to comment
Share on other sites

27 minutes ago, Snark said:

Ah, okay.  That simplifies matters.

  1. You'll make a custom PartModule, which you put on your part.
  2. It will have a method on it which you decorate with the KSPAction annotation, so that it'll be available via action group.
  3. You'll probably also want something decorated with KSPEvent annotation, so that it'll also be available via the part's right-click menu.
  4. I'll assume you'll want the numbers that control your behavior to be something that comes from your part config, and not hard-coded into the module.  So in that case, you'll also want to decorate that with the KSPField annotation.
  5. In the code that you execute when someone triggers the menu item or action group, you'll iterate through every part on the vessel and adjust its max temperature settings.
  6. When you create your part, your part config will be set up to put your PartModule on it, and to set whatever config values you want for the PartModule.

Of the above items advice, #5 is the only one I'm not totally sure about.  The thing I'm not sure about is whether the game will actually let you change the max temperature of individual parts on a vessel, in flight.  I don't know that you can't... but I don't know that you can, either.  It's something you'd have to experiment with to verify that it's possible.

Another complication that I expect you'll likely need to write code to handle, assuming that setting the max temps actually is possible:  Let's say that there are two possible states.  "Triggered" (when you have the thing turned on, so it's tweaking the max temps) and "untriggered" (when it's turned off and they have their default temperatures).  Suppose you're in the triggered state, and then you exit the game or switch away from that vessel.  I'm pretty sure that the per-part max temps aren't saved with the ship in your .sfs file.  So when you switch back to that ship, all your customized temperature settings will (I think) be gone.  If that's the case, then you'd need to run some additional code in your custom PartModule that runs when it loads up, so that it checks whether the action group is active or not; and if it is, does the iterate-over-everything-and-set-temperatures thing again.

 

this is all very useful information. here's the problem. I haven't used C# in a couple years. and I need to re-learn most things. is there a template somewhere for this?

Link to comment
Share on other sites

25 minutes ago, MrMcMuffinJr said:

I haven't used C# in a couple years. and I need to re-learn most things. is there a template somewhere for this?

When I was learning modding myself, what I found most helpful was to just download the source code from some existing mods, and use that as an example to copy from.  This is easy because all mods are required to post links to their source code. :wink:

If you're starting up from absolute scratch:

  1. Download and install Visual Studio.  It's free.  :)
  2. Create a new project.  For project type, choose "Class Library".
  3. After the project is created, go into project properties and set the .NET platform version to 3.5.  (You need to do that because that's what KSP wants, but the default is whatever-the-latest-.NET-version-is, which is more recent than that.)
  4. Under the "assembly references" tab, you'll need to add a reference to the relevant KSP assemblies.  (You can see what these are by downloading an existing mod's source code and looking at its .csproj file.)
  5. Then just start coding.  :)  Again, here's where I found it really helpful to just look at an existing mod and use that as a model.

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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