Jump to content

For each, ConfigNode, Dictionary<int, string>


Recommended Posts

Hi,

What I want to do is pretty hard to explain.

I want to load a ConfigNode named "CHANGEANYTEXT" (I know how to do this) like this one:


CHANGEANYTEXT
{
15124 = ...
45145 = ...
45744 = ....
45485 = ....
}

I've put some random numbers here because it's an example.

In my code I have a Dictionary<int, string> named dict_zh.

For each value in my ConfigNode, I want to set an int value to the corresponding value name, and string to the value of the same line.

Example :


CHANGEANYTEXT
{
15124 = example text
}

In this example, the code should add this to the dictionary:

dict_zh[15124] = "example text"

Does someone know how to do that ?

Edited by simon56modder
Link to comment
Share on other sites

From memory I think something like this will work:


ConfigNode node = "CHANGEANYTEXT"; //assign the node here as appropriate.
foreach (NodeValue val in node.Values) //NodeValue is the wrong data type, you will have to check the object browser for what type of list node.Values is and use that
{
dict.Add(Int.Parse(val.Key), val.Value); //I'm using the standard Dictionary commands here, again check the object browser for what data type squad is using exactly. This also does not check for existing key and will throw an error if val.Key already exists.
}

Hope that works as a starting point.

D.

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...