How do I add Newline or /n to a global text variable

  • Hello!

    Is there a way to add a new line in a string variable while setting the string's text? for examle:

    When I try to do it like this, "/n" is typed on the screen insead of a new line.

    Unfortunately, only by typing & Newline & in an event or /n in a text properties it works.

    Is there a way to solve this without using an event or text properties?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is this a solution ?

    Global constant text EXAMPLE = "Hello" & newline & "World"

  • Is there a way to add a new line in a string variable while setting the string's text?

    ...

    Is there a way to solve this without using an event or text properties?

    I don't think you can do it just with text within the variable, you'll need some sort of Event to handle it. You're adding the variable to the Text object using an Event at some point anyway, so it's just a matter of changing your Event.

    I've created an example capx (r233) using a for loop with tokencount and tokenat to add in newline where needed.

  • Gamesmeir and OddConfection

    OddConfection is correct, but an easier way is to use Replace

    Global text Example = "Hello/nWorld"

    then at start of layout...

    System > Set Example to Replace(Example,"/n",newline)

    (Replace will replace all occurrences, so there can be multiple /n within the string. Obviously this wont work with Constants because you can't change the value of a constant, but then whenever you use Example you will get the desired result.)

  • OddConfection is correct, but an easier way is to use Replace

    Damn, I should have thought of that.

    Just tested with this:

    Text -> Set text to replace(EXAMPLE,"/n",newline)

    Definitely the easier way to go.

  • Good idea, Thank you all!

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