Bug #14316

ConfigNode.GetValue silently editing \n out of strings

Added by HebaruSan 13 days ago. Updated 8 days ago.

Target version:
Start date:
% Done:




I wanted to represent multi-line strings with line breaks in a cfg file by embedding "\n", the standard escape sequence for a new line. In 1.2.2, this worked fine; it was read as those two literal characters, and I was able to replace them with a real newline.

As of 1.2.9, ConfigNode.GetValue seems to silently remove \n from the string before it ever gets to my code. I get the rest of the string, minus the \n. This seems odd, because the cfg files in GameData/Squad/Localization contain instances of \n used in this way.

Return the string from the cfg file in the clear, as it was in 1.2.2. Or replace it with an actual newline. Anything other than replacing it with nothing.


#1 Updated by TriggerAu 13 days ago

  • Status changed from New to Need More Info

Might need some more info on this one as GetValue is how the other strings are being read. That said, if you can add some more detail to this one on the situation, if its for modding then we'll probably park it till we have finished the modding documentation. If its a string in the stock files/code can you add the details to the ticket for us of the issue string and we can get it nailed down.

#2 Updated by HebaruSan 13 days ago

Yes, it's for modding, and parking it makes sense.

To sum up, I made my own en-us.cfg file with nodes like this:

name = inboundHyperbolicWarning
string = <&lt;0&gt;> is on an escape trajectory.\nCapture to see more transfers.

Then I loaded them:

ConfigNode langCfg = GameDatabase.Instance.GetConfigNode(url);
ConfigNode[] translations = langCfg.GetNodes("TRANSLATION");
for (int i = 0; i < translations.Length; ++i) {
string key = translations[i].GetValue("name");
string val = translations[i].GetValue("string").Replace("<<", "{").Replace(">>", "}");

In that 'val' string, the \n substring is just gone. The rest of the string is fine, including the <<0>> -> {0} translation, but there's no backslash or 'n', and there's no newline either. If I change my cfg file and my code to look for a pipe instead of a backslash, I can get it working, but since I'm hoping other users will provide translations, I'd rather use the standard string. If the modding documentation will say not to do this, then I can just wait.

#3 Updated by TriggerAu 13 days ago

  • Status changed from Need More Info to Updated
  • % Done changed from 0 to 10

Thanks for the info.

Yeah you might want to wait for info on the modders forum as the code your writing there is already in the game and you probs dont need to do that

Off the top of my head your custom file would look like this

        #LOCALIZATIONKEY = <<1>> is on an escape trajectory.\nCapture to see more transfers.

the the code is like

    string teststring = KSP.Localization.Localization.Format("#LOCALIZATIONKEY",variable);

I guarantee none of this - including the classnames - at this point as we are still working on it, but would suggest you wait for the documents on how this can be used or you will be writing code you may not mneed

#4 Updated by HebaruSan 8 days ago

OK, you can close this one. If I use the proper Localization{en-us{}} format in my cfg and call Localization.Format, the line breaks are back. I think there's still a change to existing behavior for mods that read their own strings directly out of cfg files, but it won't prevent localization from going smoothly.

Also available in: Atom PDF