Jump to content

Saving getting called more than once and overwriting my values?


Recommended Posts

EDIT: I wasn't factoring in that the OnSave() gets called for every ship that's loaded. I had to put a check for ActiveVessel in the OnSave() method. The other kerbals nearby were overriding the value. Thanks.

I have a simple OnSave() and OnLoad() for my partmodule, as seen below. The partmodule is attached to a kerbal, and so only active on kerbals.

The print() shows up in the console 4 times (3 times false and the last time true) when I quicksave on EVA.

If I put the kerbal in a capsule and quicksave,

The print() still shows up, 4 times, but all false - I never set the activated Boolean to false though.

Can anyone tell me why my code behaving this way?

        public override void OnSave(ConfigNode node)
{
config.SetValue("Window Position", _windowPosition);
print("Just saved: " + activated);
config.SetValue("Activated", activated);
config.save();
}

public override void OnLoad(ConfigNode node)
{
config.load();
_windowPosition = config.GetValue<Rect>("Window Position");
activated = config.GetValue<Boolean>("Activated");

}

Edited by TwistedMexi
I realized my mistake.
Link to comment
Share on other sites

First, what's activated?

Is it off the Kerbal.activated value? Then it makes sense to me that it goes to false when the EVA ends as the active "vessel" is now the craft and no longer the Kerbal.

Otherwise we'd need more details.

D.

Link to comment
Share on other sites

First, what's activated?

Is it off the Kerbal.activated value? Then it makes sense to me that it goes to false when the EVA ends as the active "vessel" is now the craft and no longer the Kerbal.

Otherwise we'd need more details.

D.

Sorry, I thought I might be too vague.

Activated is a boolean I've defined.

I have right-click events on the part that toggle (For example: Right-click kerbal, Select "Enable": Activated = true; || Right-click kerbal again, Select "Disable": Activated = false;)

OnGui() only draws the window if activated is true.

So I'm trying to save activated to file, and load it from file. (if the GUI was active the last time the game saved, then when you reload it, the GUI should start active).

EDIT: Also here's the code for config:

PluginConfiguration config = PluginConfiguration.CreateForType<Pluginname>();

Edited by TwistedMexi
Link to comment
Share on other sites

Okay, we are now getting into places where I don't know the answer.

However, it sounds like you need to get KSPFields involved somehow to save the value the persistence file. As far as I am aware, without the KSPFields method, your values will not save across saves.

Again, this is not something I have done myself though, but with what I currently know, that is where I would start.

D.

Link to comment
Share on other sites

Okay, we are now getting into places where I don't know the answer.

However, it sounds like you need to get KSPFields involved somehow to save the value the persistence file. As far as I am aware, without the KSPFields method, your values will not save across saves.

Again, this is not something I have done myself though, but with what I currently know, that is where I would start.

D.

Thanks. I think if someone could explain why partmodule.OnSave() is getting called multiple times, that'd be a good starting point for me. I don't see why it should be doing that, nor do I understand why it's executing my save function when I'm in the capsule - that seems to be the main problem.

EDIT: I may have figured it out. I'll post here shortly if I'm correct...

Resolved I edited my original post with the explanation. Thanks.

Edited by TwistedMexi
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...