How do I add a line break into a text object via javascript?

0 favourites
  • 3 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • I have a script within an event block that calls an imported javascript function that is within an if statement.

    This function does a few things, but among others its meant to fill the text of an object with:

    let var = "Test";

    let inst = runtime.objects.Object.getFirstInstance();

    inst.text = "newline &" + var + "& newline";

    The result I would like:

    -----

    Test

    -----

    The result I get:

    -----

    newline &Test& newline

    -----

    I have also tried Newline, /n and [br][/br], but they just get typed out.

    This part is within an imported function called within an if with information that said function calculates. I know newline would work if I set the text via event, but I really wouldn't want to make 5 new global variables that I will only use once, and spread the whole thing over a bunch of other functions just because of this missing syntax. Or copy paste a large function into the scriptblock of the event.

    Is there any way to add a text including new lines to a text object with javascript?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • newline is a Construct expression. Those cannot be directly accessed from JavaScript.

    In JavaScript, if you want a string with a newline in it, use "\n".

  • AHH, \n, not /n. My bad! Thank you for the quick answer!!

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