Solved Config reset on reload

Discussion in 'Rust Development' started by sami37, Oct 20, 2016.

  1. Hello,

    I have a problem with one of my plugin.
    I am trying to do a list of match string but when i edit config this list get reset to the default one from plugin.

    My plugin is look like that

    Code:
            private List<string> DefaultBasePoint = DefaultSRPay();        protected override void LoadDefaultConfig()
            {
                Config["SRMatch"] = DefaultBasePoint;
                SaveConfig();
    }        static List<string> DefaultSRPay()
            {
                var d = new List<string>
                {
                    "111x",
                    "222x",
                    "333x",
                    "444x",
                    "555x",
                    "666x",
                    "777x",
                    "888x",
                    "999x",
                    "99x9",
                    "9x99",
                    "x999",
                    "99xx",
                    "9xxx"
                };
                return d;
            }        void Init()
            {
                LoadDefaultMessages();
                permission.RegisterPermission("Lottery.canuse", this);
                CheckCfg("SRMatch", ref DefaultBasePoint);
                SaveConfig();
            }
            private void CheckCfg<T>(string Key, ref T var)
            {
                if (Config[Key] is T)
                    var = (T) Config[Key];
                else
                {
                    Config[Key] = var;
                    newConfig = true;
                }
            }
    

    Anyone has an idea of what is the problem?
     
  2. Maybe because of that part of Init:
    Code:
    CheckCfg("SRMatch", ref DefaultBasePoint);
    This looks on a quick fly over like its always loading ther defaults then from "DefaultSRPay".
     
  3. I am doing it for other config and it's working example for a dictionnary

    Code:
    private Dictionary<string, object> DefaultWinRates = DefaultPay();
    protected override void LoadDefaultConfig()
    {
         Config["WinRate"] = DefaultWinRates;
         SaveConfig();
    }
    void Init()
    {
        CheckCfg("WinRate", ref DefaultWinRates);
        SaveConfig();
    }