Jump to content

Help with GameParameters


Recommended Posts

I'm trying to migrate some of AGM's settings to the GameParameters window, I've been using @DMagic's Maneuver Node Evolved as guidance and thought it looked pretty straight forward.  My mod, strangely enough, is doing exactly what I wanted, but when it's present KSP is freaking out.

zb3Chdl.png

For the life of me, I can't figure out what I am doing to cause that.  I've been staring at it for an hour and don't know what I did wrong.  Please help!

Startup:

using UnityEngine;

namespace ActionGroupManager
{
    [KSPAddon(KSPAddon.Startup.MainMenu, true)]
    public class Core
    {
        CareerParameters careerSettings;
        static DebugParameters debugSettings;
        public const string ModPath = "AquilaEnterprises/ActionGroupManager/";

        private void Start()
        {
            careerSettings = HighLogic.CurrentGame.Parameters.CustomParams<CareerParameters>();
            debugSettings = HighLogic.CurrentGame.Parameters.CustomParams<DebugParameters>();
        }

        static public void AddDebugLog(string message, bool verbose = false)
        {
            if (debugSettings.basicLogging)
                if (!verbose || debugSettings.verboseLogging)
                    Debug.Log("<color=#800000ff>[Action Group Manager]</color> " + message);
        }
    }
}

Parameters:

using KSP.Localization;

namespace ActionGroupManager
{
    class CareerParameters : GameParameters.CustomParameterNode
    {
        // #autoLOC_AGM_060 = Enable Career Mode
        // #autoLOC_AGM_114 = Action Groups may only be modified if either the VAB or SPH have been upgraded to the correct tier.
        [GameParameters.CustomParameterUI("#autoLOC_AGM_060", toolTip = "#autoLOC_AGM_114", autoPersistance = true)]
        public bool enableCareer = true;

        public override GameParameters.GameMode GameMode
        {
            get { return GameParameters.GameMode.CAREER; }
        }

        public override string Section
        {
            get { return "AGM"; }
        }

        public override string DisplaySection
        {
            get {
                // #autoLOC_AGM_004 = Action Group Manager
                return Localizer.GetStringByTag("#autoLOC_AGM_004");
            }
        }

        public override int SectionOrder
        {
            get { return 1; }
        }

        public override string Title
        {
            get
            {
                // #autoLOC_AGM_005 = Career Settings
                return Localizer.GetStringByTag("#autoLOC_AGM_005");
            }
        }

        public override bool HasPresets
        {
            get { return false; }
        }
    }

    class DebugParameters : GameParameters.CustomParameterNode
    {
        // #autoLOC_AGM_066 = Basic Logging
        // #autoLOC_AGM_115 = Enable to show code event logs in the console and output file.
        [GameParameters.CustomParameterUI("#autoLOC_AGM_066", toolTip = "#autoLOC_AGM_115", autoPersistance = true)]
        public bool basicLogging = false;

        // #autoLOC_AGM_066 = Verbose Logging
        // #autoLOC_AGM_116 = Enable to show code loop logs in the console and output file. WARNING: This creates a large number of log messages!
        [GameParameters.CustomParameterUI("#autoLOC_AGM_067", toolTip = "#autoLOC_AGM_116", autoPersistance = true)]
        public bool verboseLogging = false;

        public override GameParameters.GameMode GameMode
        {
            get { return GameParameters.GameMode.ANY; }
        }

        public override string Section
        {
            get { return "AGM"; }
        }

        public override string DisplaySection
        {
            get
            {
                // #autoLOC_AGM_004 = Action Group Manager
                return Localizer.GetStringByTag("#autoLOC_AGM_004");
            }
        }

        public override int SectionOrder
        {
            get { return 3; }
        }

        public override string Title
        {
            get
            {
                // #autoLOC_AGM_007 = Debug Settings
                return Localizer.GetStringByTag("#autoLOC_AGM_007");
            }
        }

        public override bool HasPresets
        {
            get { return false; }
        }

        public override bool Enabled(System.Reflection.MemberInfo member, GameParameters parameters)
        {
            if (member.Name == "verboseLogging")
                return basicLogging;

            return true;
        }
    }
}

 

Link to comment
Share on other sites

I don't think you can initialize your settings in the main menu like that, since there is no current game. That might be wreaking havoc with the stock parameters somehow. Try waiting for another scene once the game has loaded.

Other than that, maybe the static for DebugParameters in the Core class, or maybe make sure the parameter classes are public. I can't see anything obviously wrong with anything else.

Link to comment
Share on other sites

@DMagic Thanks, but that actually works fine.  I suspect GameParameters are loaded before Start is executed. You were right you can't but that wasn't the issue, it just caused NullRefs down the road.  Also, inheriting MonoBehaviour helps (just a wee bit).

 

I actually just now found the problem though and it would be funny if it weren't so sad how much time I wasted on it.

So, yesterday my SSD started to get full, so I moved my KSP dev test environment to my HDD.  Then I had to re-reference UnityEngine and Assembly-CSharp, which had their Copy Local turned back on.  Then my post build event copied everything off to the GameData Folder and I didn't bother to go look at it and... here we are.  There was never anything wrong with the code.

Some days I just want to go back to bed.

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