0 Favourites

Using newline in a text variable

  • I want to read values for Text objects from some variables. But i couldn't create a newline.

    Thanks.

    <img src="https://dl.dropboxusercontent.com/u/70704903/ForumQuestions/20/event.png" border="0">

    Here is my capx (r152)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I don't if that is possible. Because the "newline" command must be outside the string:

    "first line" & newline & "second line"

  • Why don't you set the text diretly using the first 2 variables?

    SetText > variable 1 & newline & variable 2

  • Ignore my last post.

    But still, I don't think you can do that.

    The variable reads the whole value as string, I guess.

  • You can't input it in the editor, but you can save them dynamically in the game. So if a text has line breaks and you save text.text into a variable, the line breaks will be retained.

    I did some testing, when outputing a string with linebreak as json it is output is

    \n but manually entering it like that in a string won't transform it into a newline.

  • I don't think it's possible to create a new line in the variable's value when you declare it. You have to make two variables and then use the newline expression in the action

  • thiago

    In my new projects i used some big text variable instead of arrays. For example you can look at this project. It isn't possible to give a default values for array, so using a text variable is practical.

    I plan to group every text object values in a big text variable .

  • "It isn't possible to give a default values for array"

    ???

  • I mean it's not practical.

    For example you want to save 100 different values in an array. You need 100 different actions. But you can create a one text variable and read any value with tokenat

    Here is my system. Every text has a different instance variable(no). I give different values to texts like this

    <img src="https://dl.dropboxusercontent.com/u/70704903/ForumQuestions/20/longtext.png" border="0" />

    <img src="https://dl.dropboxusercontent.com/u/70704903/ForumQuestions/20/witharray.png" border="0" />

  • I'm not sure what outcome you are getting, but looking at the first post, Variable2 would be correct. If you're outcome is that you are only seeing "first line" with no second line, then you should try resizing your Text objects' height in the layout editor or in an event!

  • Thanks Jase00

    I also shared a capx

    You can see that all texts height are 281 pixels. So they're long enough to carry another line of texts.

  • Oh, I see what the problem is now! I tried the Alt code (Alt+013) for newline directly in the editor but that didn't work. I don't think this will really be rectifiable.

    If I had to give a piece of advice when working with large amounts of text, it would be to write it all in a .txt and load it into the "Files" section of your project and call on it when you need to read text (I haven't really done this before, but Ashley has advised it on people before when handling text)

    Either that, or have a ' Start Of Layout> Set Variable 1 to "firstline"&newline&"secondline" '.

    Hope I was of help!

  • I mean it's not practical.

    For example you want to save 100 different values in an array. You need 100 different actions. But you can create a one text variable and read any value with tokenat[/IMG]

    Not really 100 actions. More like 1 event and action:

    <img src="http://666kb.com/i/cjte950xdbs4r3lvn.png" border="0" />

  • Thanks for everyone. I found a solution

    <img src="https://dl.dropboxusercontent.com/u/70704903/ForumQuestions/20/textsolution.png" border="0" />

  • I liked that solution, mindfaQ .

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