1. Hello, I tried to loop through the config. Here is what I tried
    Code:
            protected override void LoadDefaultConfig()
            {
                ClearConfig();
                Config["Preset", "Messages", "NoPermission"] = "You have no permission to use this command!";
                Config["Preset", "Messages", "Msg1"] = "Hello!";
                Config["Preset", "Messages", "Msg2"] = "How are you?";
                Config.Save();
            }        [ChatCommand("msgs")]
            void ShowMsgs(BasePlayer player)
            {
                foreach (var current in Config)
                {
                    SendReply(player, current.Messages.Msg1);
                    SendReply(player, current.Messages.Msg2);
                }
            }
    
    Config looks like this:

    Code:
    {
        "Preset": {
            "Messages": {
                "NoPermission": "You have no permission to use this command!",
                "Msg1": "Hello!",
                "Msg2": "How are you?"
            }
        }
    }
    and im getting an error

    Code:
    error CS1061: Type `System.Collections.Generic.KeyValuePair' does not contain a definition for `Messages' and no extension method `Messages' of type `System.Collections.Generic.KeyValuePair' could be found. Are you missing an assembly reference?
    What am I doing wrong? :c
    idk how to do this
     
    Last edited by a moderator: Jul 15, 2015
  2. There is an example of config messages in pretty much every plugin. You can look at my Death Msg plugin for an example I know of off the top of my head.
     
  3. basicly the messages were only an example. What I actually wanted is to loop through the config. I know looping through for messages is bullshit. Im going to look into your Death Messages plugin anyways
    [DOUBLEPOST=1436970185][/DOUBLEPOST]Umm. You are getting the config. But you are only getting the Messages part. How would I be able to loop through the whole config?
    Code:
    var temp = Config.Get<Dictionary<string, Dictionary<string, object>>>("Messages");
    Config is so much harder in C# than in Lua..
     
    Last edited by a moderator: Jul 15, 2015
  4. Its not that it is harder in Lua it is because you haven't taken the time to learn about the underlying structure of Configs.

    Your error message gives you plenty of information to go off of. The Config is just a bunch of nested objects in a Dictionary. When you loop through a dictionary you get back key value pairs.
    Code:
    foreach (var current in Config)
                {
                    Puts(current.Key.ToString());
                    Puts(current.Value.ToString());
                }
     
  5. Yeah, you are right. I dun know much about Configs itself. like that. With current.Key.ToString() I get the name of the current Dictionary. In this case "Preset". To now get the stuff inside I need to use the thing I posted from your code?
    [DOUBLEPOST=1436976137][/DOUBLEPOST]
    Code:
    var mgs = Config.Get<Dictionary<string, Dictionary<string, object>>>(current.Key.ToString(), "Messages");
    ?
    [DOUBLEPOST=1436976970][/DOUBLEPOST]uhh that stuff confuses meh ---
     
    Last edited by a moderator: Jul 15, 2015
  6. Why do you want to loop through the config in the first place.
     
  7. Because the same reason why I am doing it in Better Chatname. To make ppl able to create their own groups with prefix etc. I wanna rewrite that plugin in C#. And I also need it for another new plugin which works basicly the same.
     
  8. Still doesn't mean you have to loop through the config dictionary. You need to structure your group setup with a list of groups which is pretty much a listing of key value pairs.
     
  9. that means? :c
     
  10. Say your config looked like this, you would use foreach(var kv in Config){ //Stuff here for config} as long as you don't plan on adding anything else to the config. If you plan on adding anything else I would suggest using the datafile system to load your groups and not a config.

    Code:
    {
    "owner":{
       "NameColor":"orange",
       "Permission":"color_owner",
       "Prefix":"[Owner]",
       "PrefixColor":"orange",
       "TextColor":"white",
       "Rank": 4
      },
    "mod":{
       "NameColor":"lime",
       "Permission":"color_mod",
       "Prefix":"[Mod]",
       "PrefixColor":"yellow",
       "TextColor":"white",
       "Rank": 3
      }
    }
    For this example we will use the config that will always have the same structure as above.

    pseudo code.

    foreach(var group in Config)
    {
    string groupName = group.Key.ToString();
    Dictionary<string, object> groupData = group.Value;
    //Do w.e you want with your group data.
    }
     
  11. ty, I will try working with it.
    So for example I will grab the Permission with
    string perm = groupData.Permission;
    right?