Jump to content

Would it be possible to get VesselModules available in the editor


Recommended Posts

Quoting from the 1.1 release notes:

Save/Load (and KSPField) support for VesselModules.

From what I can tell, VesselModules are only active and available in flight.  Would it be possible to have them available in the Editors as well?  I'd like to be able to store some static information in a craft file without having to add a part.

 

 

Link to comment
Share on other sites

The answer to my best of my knowledge is no.

I delayed answering because I was hoping someone else would have a different answer but it looks like not.

The core issue is that there is no "vessel" object, let alone an instance of the actual Vessel class in the editor.

The only possibility I can think of is hooking into the ShipConstruct config node when a save happens and then reading those values back from the ProtoVessel object when a vessel is first launched somehow.

I don't have a clue how you'd go about that however.

In all my mods I just added a partModule to use as data storage so I've never actually though about this question before.

D.

Link to comment
Share on other sites

You don't have to physically add a part, just make your addon add/update your custom persistence PartModule to the root part maybe triggered by "OnEditorShipModified" and "OnVesselChange" events.

Link to comment
Share on other sites

@Ziw How do you make sure your root part gets your PartModule without simply adding it to every part in the game? Because my mods deal with craft control, I added it to all parts with ModuleCommand instead of using the root part.

Between the fact that almost any part type can be your root part, and the ability to change the root part, I don't find using the "root part" a reliable way of dealing with this.

D.

Link to comment
Share on other sites

Well, since I'm already adding a module to every command pod, I'm just going to add this data field to each one and then add code to keep all the command-pods up-to-date in regards to this field.  

Not too happy about it, but seems that there is no other easy way to do this.  

13 hours ago, Diazo said:

The only possibility I can think of is hooking into the ShipConstruct config node when a save happens and then reading those values back from the ProtoVessel object when a vessel is first launched somehow.

 

Can you show me how to do that?  I'd like to be able to have a function called whenever a save of a craft file is done, haven't yet figured out how to do that.

Thanks

Edited by linuxgurugamer
Link to comment
Share on other sites

No, I don't know how you would go about that. I made that comment because I know that the ShipConstruct is the object type that the editor serializes to the .craft file and that the ProtoVessel object is what the .craft gets loaded into that flight mode then converts into an actual vessel. In theory you can hook into this stuff but I've never tried.

On the triggering a function on save in the edtior, I don't know the current details, in older KSP versions (before the GUI overhaul) I actually had to hook into the buttons and their OnClick() events to trigger on a save event in the editor. One catch is that it doesn't always save to the NamedCraft.craft file, when you go to the pad via the Launch button, the editor saves to the AutoSave.craft file and loads from that on the pad, not from NamedCraft.craft file.

If you can hook the ShipConstruct, KSP will take care of that for you, but if you are writing to your own data file based on Ship Name, you'll have to account for that.

As you mention you do have a partModule, it is much simpler simply to use it for this. Even for calling the function on a save event, add that code to your partModule's OnSave method that KSP calls for you. As long as it has code to make sure it only runs once per save event (as multiple partModules would call the function multiple times for the same save event) that is probably a better way to go.

D.

Edited by Diazo
Link to comment
Share on other sites

1 hour ago, Diazo said:

As you mention you do have a partModule, it is much simpler simply to use it for this. Even for calling the function on a save event, add that code to your partModule's OnSave method that KSP calls for you. As long as it has code to make sure it only runs once per save event (as multiple partModules would call the function multiple times for the same save event) that is probably a better way to go.

 

That's an idea, thanks

Link to comment
Share on other sites

2 hours ago, Diazo said:

As you mention you do have a partModule, it is much simpler simply to use it for this. Even for calling the function on a save event, add that code to your partModule's OnSave method that KSP calls for you. As long as it has code to make sure it only runs once per save event (as multiple partModules would call the function multiple times for the same save event) that is probably a better way to go.

 

Ok, so, if there are multiple parts with the module, will the OnSave get called sequentially (ie:  first module, then second module, etc), or do I need to worry about possible race conditions (ie:  multiple modules running the onSave at the same time)

Link to comment
Share on other sites

10 hours ago, Diazo said:

@Ziw How do you make sure your root part gets your PartModule without simply adding it to every part in the game?

I presume @Ziw was referring to using a KSPAddon to programatically add your data module to the root part of the vessel (ie. SortedShipList[0].Modules.Add(...);). Don't know if the fact it isn't in the prefab is going to cause issues when the flight vessel is created since I've never done anything of the like

Link to comment
Share on other sites

Bit late, but might as well contribute

On 6/2/2016 at 11:05 AM, linuxgurugamer said:

Ok, so, if there are multiple parts with the module, will the OnSave get called sequentially (ie:  first module, then second module, etc), or do I need to worry about possible race conditions (ie:  multiple modules running the onSave at the same time)

It's called sequentially.  Why would it matter though - OnSave really shouldn't change the state of the PartModule and each module is writing to a different ConfigNode.

On 6/2/2016 at 5:29 PM, Crzyrndm said:

I presume @Ziw was referring to using a KSPAddon to programatically add your data module to the root part of the vessel (ie. SortedShipList[0].Modules.Add(...);). Don't know if the fact it isn't in the prefab is going to cause issues when the flight vessel is created since I've never done anything of the like

This would indeed cause issues.  KSP only creates PartModules when parsing the part - after that they're all taken from the prefab.  So your PartModule would not survive into the flight scene and KSP would spit out a warning.

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