Author Topic: How do I embed a new line feed in text sent to a label?  (Read 10769 times)

gevarre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
How do I embed a new line feed in text sent to a label?
« on: June 07, 2013, 02:07:21 PM »
I need to send a text string to a label at runtime that consists of several segments seperated by new line feed character. The NGui docs say to use \n in the text string to do this, but it doesn't actually work. It just prints that along with the rest of the text on one long line.

I have Encoding checked, but unfortunately, the docs are obviously for an outdated version of the label and the options are not the same, so I don't know if things have changed or what. I am using the full version of NGui, not the free one, if that makes a difference.

Does anyone know how to do this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I embed a new line feed in text sent to a label?
« Reply #1 on: June 07, 2013, 03:27:10 PM »
The obvious question is -- do you use \\n or \n? Because they are different things. \n is actually one character (the 'newline'), while \\n means '\' followed by 'n' which is two characters, and is obviously not the same thing. A string like this: "hello\nworld" will be two lines, assuming it's specified via code. If you read the text from some file however, \ and n will be two separate characters.

gevarre

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: How do I embed a new line feed in text sent to a label?
« Reply #2 on: June 07, 2013, 06:37:16 PM »
Sorry, I should have said - I'm trying to make an in-game scoreboard by building a string from player names stored in an array and sending that string to the text field of the UILabel using the "Set Property" action in Playmaker. For example:
"Player 1 \n Player 2 \n Player 3"

Which, I was assuming from the documentation, was supposed to work, though as I say, it looks to be rather out-of-date. It updates the text just fine, it just ignores the line feeds.

If this doesn't work, then what would be the correct way to do this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I embed a new line feed in text sent to a label?
« Reply #3 on: June 07, 2013, 08:04:45 PM »
The problem is Playmaker's script. It has been brought up in the past. Tell Playmaker dev (Alex) to change his script's text input to be a text area instead -- this will allow people to input multiple lines, just like selecting an NGUI label and inputting text there.

jeanfabre

  • Guest
Re: How do I embed a new line feed in text sent to a label?
« Reply #4 on: June 10, 2013, 04:26:31 AM »
Hi,

 Just ran a test, and it seems to work just fine. double check with this package:

http://hutonggames.com/playmakerforum/index.php?topic=4103.msg19243#msg19243

bye,

 Jean


caesarhernandez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: How do I embed a new line feed in text sent to a label?
« Reply #5 on: August 03, 2014, 05:19:38 PM »
Hey all,

I know this topic hasn't been visited in a while , but I am having problems getting a newline break and tabs into a label.

The label's text value is being set from a string that was retrieved from a www call. This string was built in c# and I tried using:
Environment.NewLine
and
'\n'
and
'\t'

I just cannot get a newline and tabs to work with a UILabel. Jean, I cannot get your project to work. It says it is missing a script

caesarhernandez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: How do I embed a new line feed in text sent to a label?
« Reply #6 on: August 03, 2014, 05:25:36 PM »
Please disregard. The problem is that I'm returning JSON and the parser is for some reason not recognizing the newlines. Returning a string only works fine.