Jump to content

ScenarioModule help needed (solved)


Recommended Posts

I'll leave this here, but essentially, I wasn't setting the value in the correct place, so it wasn't being saved.

 

I'm having a problem getting a ScenarioModule working.  I'm trying to save a string which is set while inside the editor, so it can be used the next time entering the editor.

While I see it in the persistent.sfs file, it never gets set.  I even tried setting the value from inside the module where I use it, but it still didn't get saved.

Obviously, I'm missing something but don't know what.

Any ideas:

Here is the code

namespace CorrectCoL
{
     [KSPScenario(ScenarioCreationOptions.AddToAllGames, new GameScenes[] {GameScenes.EDITOR})]
    public class CorrectCoL_Persistent : ScenarioModule
    {
        static public CorrectCoL_Persistent Instance;

        bool loaded = false;

        [KSPField(isPersistant = true)]
        public string lastSelectedPlanet = "";

        private void Start()
        {
            Instance = this;
        }

        new public void OnAwake()
        {
            Debug.Log("CorrectCoL_Persistent.Awake");
            if (lastSelectedPlanet != "")
                PlanetSelection.setSelectedBody(lastSelectedPlanet);
        }
        override public void OnSave(ConfigNode node)
        {
            Debug.Log("CorrectCoL_Persistent.OnSave:" + PlanetSelection.selectedBody.name);
            lastSelectedPlanet = PlanetSelection.selectedBody.name;
            base.OnSave(node);
        }
    }
}

 

An alternative try:

namespace CorrectCoL
{
     [KSPScenario(ScenarioCreationOptions.AddToAllGames, new GameScenes[] {
        GameScenes.SPACECENTER,
        GameScenes.EDITOR,
        GameScenes.FLIGHT,
        GameScenes.TRACKSTATION,
        GameScenes.SPACECENTER
     })]
    //[KSPAddon(KSPAddon.Startup.EditorAny, false)]
    public class CorrectCoL_Persistent : ScenarioModule // MonoBehaviour
    {
        static public CorrectCoL_Persistent Instance;        

        [KSPField(isPersistant = true)]
        public string lastSelectedPlanet = "";

        override public void OnAwake()
        {
            Instance = this;
        }

        void Start()
        {
            Debug.Log("CorrectCoL_Persistent.Start");
            if (lastSelectedPlanet != "")
                PlanetSelection.setSelectedBody(lastSelectedPlanet);
        }

    }
}

 

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