Author Topic: Having trouble with \n  (Read 1514 times)

bobbyk

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Having trouble with \n
« on: October 25, 2014, 07:46:24 PM »
Hello,

I want my labels to have line breaks but when I use \n nothing happens.  Same deal both in the main UILabel script and if I feed it using Playmaker.

Am I doing this wrong?  I'm simply putting something like "Hello how \n are you?" into the field and the outputs looks exactly the same... is that wrong? also tried \\n

This guy was also getting the same results he has a picture attached  http://hutonggames.com/playmakerforum/index.php?topic=4103.msg19243;topicseen#msg19243
« Last Edit: October 25, 2014, 10:57:14 PM by bobbyk »

bobbyk

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Having trouble with \n
« Reply #1 on: October 25, 2014, 11:22:11 PM »
searched and searched the forums but still confused.  here's another thread about this but I still don't understand how to make this work through playmaker's "set property" I still see \n every time.  i don't understand how to implement this code Aremook posted.  I might just want to use UItextlist but I'm also not sure how that accepts things like line breaks.

http://www.tasharen.com/forum/index.php?topic=5041.msg24130#msg24130

public UILabel myUILabel;
public string myText;

void Start ()
{
   myUILabel.text = myText.Replace("\\n", "\n");
}
« Last Edit: October 25, 2014, 11:40:11 PM by bobbyk »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Having trouble with \n
« Reply #2 on: October 26, 2014, 09:18:47 PM »
I don't know what playmaker does. From NGUI's point of view, it simply displays what you tell it to. If you type in "hello\nworld" in inspector in Unity, the '\' and 'n' are two characters. They don't get translated to a new line, which is just one character. The code snipplet you pasted (label.text = oldText.Replace("\\n", "\n");) actually replaces the two character sequence with a single new line character.

So instead of setting label's text as "label.text = oldtext;", use the line above.