Using newline in a text variable

Get help using Construct 2

Post » Wed Dec 04, 2013 4:23 pm

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

Thanks.


Here is my capx (r152)
B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Post » Wed Dec 04, 2013 4:45 pm

I don't if that is possible. Because the "newline" command must be outside the string:

"first line" & newline & "second line"

Thiago Rocha
[email protected]
B
17
S
4
G
5
Posts: 41
Reputation: 4,264

Post » Wed Dec 04, 2013 4:48 pm

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

SetText > variable 1 & newline & variable 2
Thiago Rocha
[email protected]
B
17
S
4
G
5
Posts: 41
Reputation: 4,264

Post » Wed Dec 04, 2013 4:50 pm

Ignore my last post.
But still, I don't think you can do that.
The variable reads the whole value as string, I guess.
Thiago Rocha
[email protected]
B
17
S
4
G
5
Posts: 41
Reputation: 4,264

Post » Wed Dec 04, 2013 4:53 pm

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.mindfaQ2013-12-04 16:55:25
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Dec 04, 2013 5:03 pm

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
B
45
S
13
G
2
Posts: 173
Reputation: 5,331

Post » Wed Dec 04, 2013 5:06 pm

@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 .

mrcgkh2013-12-04 17:15:32
B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Post » Wed Dec 04, 2013 5:15 pm

"It isn't possible to give a default values for array"
???
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Dec 04, 2013 5:20 pm

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



mrcgkh2013-12-04 17:45:07
B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Post » Wed Dec 04, 2013 5:38 pm

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!
B
51
S
20
G
10
Posts: 571
Reputation: 9,819

Next

Return to How do I....?

Who is online

Users browsing this forum: rayolf and 6 guests