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

Get help using Construct 2

Post » Wed Apr 19, 2017 12:23 pm

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

Image

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

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!
B
4
S
1
Posts: 6
Reputation: 262

Post » Wed Apr 19, 2017 2:04 pm

Is this a solution ?

Global constant text EXAMPLE = "Hello" & newline & "World"
B
3
Posts: 3
Reputation: 181

Post » Wed Apr 19, 2017 3:57 pm

Gamesmeir wrote: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.
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
32
S
9
G
7
Posts: 444
Reputation: 6,731

Post » Thu Apr 20, 2017 3:56 am

@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.)
B
94
S
33
G
20
Posts: 438
Reputation: 17,605

Post » Thu Apr 20, 2017 6:11 am

AllanR wrote: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.
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
32
S
9
G
7
Posts: 444
Reputation: 6,731

Post » Thu Apr 20, 2017 4:33 pm

Good idea, Thank you all!
B
4
S
1
Posts: 6
Reputation: 262


Return to How do I....?

Who is online

Users browsing this forum: Mayfly and 8 guests