1. Im trying to set an Array or a List in the config and then loop through it but I failed :c
    Idk if Im just too stpd...
    What I tried:

    Code:
    //---------------------------------------------------------------------------------//        protected override void LoadDefaultConfig()
            {
                Config.Clear();
                Config["Test"] = new string[] { "Hello", "World!" };
                SaveConfig();
            }//---------------------------------------------------------------------------------//        protected override void LoadDefaultConfig()
            {
                Config.Clear();
                Config["Test"] = { "Hello", "World!" };
                SaveConfig();
            }//---------------------------------------------------------------------------------//        protected override void LoadDefaultConfig()
            {
                Config.Clear();
                Config["Test"] = new List<string> { "Hello", "World!" };
                SaveConfig();
            }//---------------------------------------------------------------------------------//            foreach(string current in Config["Test"])
                {
                    Puts(current);
                }
    
     
  2. Code:
    protected override void LoadDefaultConfig() {
        var listIsList = new List<object>() {
                        "item1",
                        "item2"
                    };
        Config["ListIsList"] = listIsList;
    }
    Works fine?
     
  3. um ohkay, may you need to declare it as a var first? and not just do It like I done? As mine didn't work.
    EDIT: Ouhh you used a list of objects... I tried a list of strings
    [DOUBLEPOST=1434664679][/DOUBLEPOST]@Hatemail Looping through still does not work :c
    Code:
    foreach statement cannot operate on variables of type `object' because it does not contain a definition for `GetEnumerator' or is inaccessible
     
    Last edited by a moderator: Jun 18, 2015
  4. Use Dictionary, good object
    Code:
    public Dictionary<string, Dictionary<int, Dictionary<string, string>>> WorldTables = new Dictionary<string, Dictionary<int, Dictionary<string, string>>>();
     
  5. Yeah and what am I suppose to do with that? You don't post your code so I don't know the context of the error other than what its says.

    Example loop:
    Code:
     var listIsList = new List<object>()
            {
                "item1",
                "item2"
            };        foreach (var test in listIsList)
            {
                Console.WriteLine(test);        }
     
  6. Thats exactly how I did it... Just in the config
    Code:
    5:48 PM [Error] Test plugin failed to compile!
    5:48 PM [Error] Test.cs(36,39): error CS1579: foreach statement cannot operate on variables of type `object' because it does not contain a definition for `GetEnumerator' or is inaccessible
    
    Code:
            protected override void LoadDefaultConfig()
            {
                Config.Clear();
                var WordList = new List<object>() { "Hello", "World!" };
                Config["words"] = WordList;
                SaveConfig();
            }        [ChatCommand("test")]
            void cmdTest(BasePlayer player, string cmd, string[] args)
            {
                foreach(var word in Config["words"])
                {
                    Puts(word);
                }
            }
    
     
    Last edited by a moderator: Jun 19, 2015
  7. Yeah and you expected that to work why? You never converted the object to a List.
    The easiest way to do the correct conversion would be.
    var listOfConfigPath = Config.Get<List<string>>("ConfigPath");
     
  8. Umm I just added that line t the cmdTest() now... That works
    Code:
    List<string> WordList = Config["words"] as List<string>;
     
    Last edited by a moderator: Jun 19, 2015