Best way to apply formatting to text object after setting from Array?

0 favourites
  • 14 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hi,

    looking for a good way to format text upon setting a text object to an Array i.e. on any touch>set text object to Array.at(0, 0) but the text object doesn't show the line break.

    I tried adding a line break in the actual paragraph in the Array but it disregards this upon setting the text object.

    My only thoughts are that it may be something to do with Token at or even Find expression but don't fully understand it myself...

    Thank you

  • Set array value to "text"&newline&"moretext"

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Cheers mate.

    Do you mean split the text into two array items i.e. set text object to Array.at(0, 1) &newline& Array.at(0, 2) ?

  • That would work too if its appropriate to the game in some way, but what I mean here is you set the array at 0,0 to the literal entry of "It would be nice to have a line break here"&newline&"but as you can see.." then when you set text to array at 0,0 it would have the line break.

  • Thanks.

    To split it would be very messy.

    I tried the array value way and doesn't seem to work.

    here is a link to the project file https://we.tl/t-sUwW0Q26DC ....

  • Ah right if you set the array value it works but if you load from JSON it doesn't I guess you could try the array.at(0,0)&newline&array.at(0,1) and split out the text in this way. Can't think right now how I would get that work with JSON, converting to str doesn't do it.

  • Ok well the split way would work anyway so that's good

  • Yeah I can't work it out with JSON because it doesn't use the command but thinks of it all as text. If you use set text from array then you can make use of newline. So looks like the split out will work best, good luck :)

  • Ideally you should be able to use the BB code so [br][/br] but this doesn't seem to work so we can see if anyone else has an idea on this.

  • Depending on how you're actually displaying your text, this may or may not help. But to apply formatting in my dialogue system, I run the strings through a formatting function. (I believe it was actually Kyatric that came up with this method.)

    So any BB Code or line breaks are written into the JSON file (using round brackets where applicable), then the function replaces that with the correct BB Code tags.

    I talk about it in this tutorial, and there should be a project file attached.

  • Depending on how you're actually displaying your text, this may or may not help. But to apply formatting in my dialogue system, I run the strings through a formatting function. (I believe it was actually Kyatric that came up with this method.)

    So any BB Code or line breaks are written into the JSON file (using round brackets where applicable), then the function replaces that with the correct BB Code tags.

    I talk about it in this tutorial, and there should be a project file attached.

    Thanks for sharing this, that is an interesting way of looking at it. I still find it strange how the text object which allows BB code makes use of b for bold but doesn't seem to support br for line break, it would be much easier!

  • Here's a simple script example using <BR> as a break.

    Format example

  • Guys,

    I have 3 ways of doing this now. Thank you very much. Works brill

    Cheers

  • sizcoz this is really good and so simple. My first time using javascript code. Thanks mucho

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)