Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: playsteven on June 14, 2016, 09:43:14 AM
-
Hey there,
I've created a simple action to pass a string for new text to TextMesh Pro, and I'm having issues with "\n" in the string:
say the string is "hello\nthere"
textmeshPro.text = stringToUse.Value;
displays:
hello\nthere
but if I change the action
textmeshPro.text = "hello\nthere";
displays:
hello
there
I've also tried
string messageToTry = stringToUse.Value;
textmeshPro.text = messageToTry;
displays:
hello\nthere
Why the difference when the string contents are exactly the same?
Thanks,
Steven
-
I followed the advice at http://hutonggames.com/playmakerforum/index.php?topic=3637.0
Done a string replace "\n" with the new line character and it works a treat.
Still, wouldn't mind knowing why this happens :)
-
Hi,
It's because the character \ is understood differently when scripted in c# then when inputed within a string variable in PlayMaker. It's known as an "escape" character which allow coders to insert custom characters easily.
http://www.codeproject.com/Articles/371232/Escaping-in-Csharp-characters-strings-string-forma
By doing a copy paste, you actually copy the real unicode reference of the "newline" character, not the litteral backslash.
Bye,
Jean
-
Thanks, Jean,
I find it invaluable to understand why something happens the way it does.
All the best,
Steven