playMaker

Author Topic: Getting text into an NGui label text field with line feeds?[SOLVED]  (Read 12296 times)

Gevarre

  • Playmaker Newbie
  • *
  • Posts: 49
Anyone have any luck getting a text string into an NGui label with line feeds?

By that I mean, I'm trying to make an in-game scoreboard. I get the players' names from an array and put them all together with "\n" between each one, so it ends up like this:

Player 1 \n Player 2 \n Player 3

Then I send it to NGui using a SetProperty action linked to the text field of the label. The text gets there all right. it's just that it prints it all on one line.

I'm using "\n" because that's what their docs say the label recognizes, but evidently only "through code" and not just as a text string. I got that explanation from a thread I started there, but so far no explanation as to what to actually do.

Just wondering if anyone has tried to do this. As I say, it's for a scoreboard, so it'll display things like health, kills, etc. If there's a better way to do this (With Ngui), I'd be grateful for any help or guidance.
« Last Edit: September 09, 2013, 05:26:16 AM by jeanfabre »

Satrio

  • Junior Playmaker
  • **
  • Posts: 67
Re: Getting text into an NGui label text field with line feeds?
« Reply #1 on: June 08, 2013, 01:48:57 PM »
It used to work with /n before the latest update. I have been bitching about it at NGUI forums, but apparently I am wrong, it never worked and I should have done it using a get.property that doesn't exist when you use PM..

I think you can do it with "build string" but that seems idiotic, when it just used to work before..

tankun

  • Playmaker Newbie
  • *
  • Posts: 26
Re: Getting text into an NGui label text field with line feeds?
« Reply #2 on: June 10, 2013, 02:16:32 AM »
Here's an idea.

Create a single NGUI prefab for the scoreboard name (or more for score and stuff). Get the number of the players using Array List Count. (or convert into an Array List temporarily if you're using a Hash Table). Create an instance of the NGUI prefab using Create Object and assign the next Array List item. You can use Array List Get Next action here. Repeat until Array List count is reached. You can also create an Int variable for screen Y position. Subtract -say 2 pixels- from it every time an item is listed. And place the next NGUI prefab into that Y location so every object is listed under the previous one. This way you can also check if the screen area limit is reached as well.

You can create an fsm state in the NGUI prefab with Destroy Self action with specific global event like "ScoreBoard / Destroy Self". When you want to clear the list, create a Send Event Action (from a different object) with Broadcast All, "ScoreBoard / Destroy Self". Every scoreboard prefab in the hierarchy will destroy itself.

I used this technique with NGUI when I was creating an inventory system. Works like a charm.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Getting text into an NGui label text field with line feeds?
« Reply #3 on: June 10, 2013, 02:54:06 AM »
Hi,

 I just tested and it works just fine, I might not getting the actual issue here.

I use the action "build string", and as the separator I put \n then I set the text property of a ngui label and it's properly showing each entries line by line.

I have attached my test if you want to check it out.

bye,

 Jean

Gevarre

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Getting text into an NGui label text field with line feeds?
« Reply #4 on: June 10, 2013, 12:56:49 PM »
Weird. I'm not getting the same results you are.

I made a new, empty project, imported Playmaker and NGui and your LineFeedText.unitypackage, then just hit play. I get what's in the attached image.

Gevarre

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Getting text into an NGui label text field with line feeds?
« Reply #5 on: June 10, 2013, 06:15:21 PM »
Update: The above test was done on a windows machine. I just did the same thing with a completely fresh install of Unity on a Mac and got the same thing.

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: Getting text into an NGui label text field with line feeds?
« Reply #6 on: June 10, 2013, 07:22:06 PM »
I thought actually hitting enter in the separator field worked?
... or was it that you had to copy paste an 'enter' from a text file?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Getting text into an NGui label text field with line feeds?
« Reply #7 on: June 11, 2013, 01:09:08 AM »
Hi,

 Ok, odd that it works just fine here, I am on mac. I'll run some test when I get a chance to go on my windows machine, probably this afternoon.

Copying the enter char of a text file should work too, but hitting enter will not, UNLESS you have a custom action editor, OR the string is extracted from a text asset.

bye,

 Jean

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Getting text into an NGui label text field with line feeds?
« Reply #8 on: August 25, 2013, 11:56:02 AM »
I recently stumbled across this editor script for windows users to enter line feeds:
http://blog.almostlogical.com/2011/12/19/unity-editor-lesser-known-features/

Direct link to script:
http://blog.almostlogical.com/resources/InsertNewLine.cs

It's also a pretty awesome Unity blog!