newline in text object

For developers using the Construct 2 Javascript SDK

Post » Thu Mar 29, 2012 2:00 am

I insert a text object called Text2.

Now in an action I set the text of this to an expression from a plugin object called texter. (texter.setit)

now setit sets returns text like this:

     exps.getinfo = function (ret)     
     {
          currentinfo=currentinfo.replace("& Newline &",Newline);
           ret.set_string(currentinfo);          
     };

now currentinfo is a global javascript variable and where i want newlines i insert the text "& Newline &", now when I return the string to the Text2 object i replace all "& Newline &" with Newline. But it doesnt work.

So the question is can you insert some text code to let construct text object know that there should be a new line here like maybe " line 1 \n\r line 2" would show on screen like:

line 1
line 2


Oh how complex...
B
7
S
1
Posts: 65
Reputation: 821

Post » Thu Mar 29, 2012 12:44 pm

Can you link your plugin?
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Thu Mar 29, 2012 12:52 pm

why, its simple question.

i.e when you set the text value for text object using a string returned from an expression how do you specify new lines?
B
7
S
1
Posts: 65
Reputation: 821

Post » Thu Mar 29, 2012 6:02 pm

In a plugin:
     exps.NewLine= function (ret, line1, line2)
     {
          ret.set_string(line1+"\n"+line2);
     };


in c2: set text to myPlugin.NewLine("first line", "second line")
________
In construct:
set text to ("line1"&Newline&"line2")
The word Newline isn't a text/string.
Joe72012-03-29 18:09:45
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Thu Mar 29, 2012 6:11 pm

@rafhelp - you seem to be confused, none of your code makes sense... newline is an expression in Construct 2's event system only and makes no sense at all in Javascript. Construct 2 replaces newline with '\n' by the time it reaches any plugin. So in your plugin you do not need to worry about line breaks at all. The user will simply use the newline expression where they want it in the event system, and your plugin will receive a string with \n in it.

Edit: moving to SDK forumAshley2012-03-29 18:11:24
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Fri Aug 03, 2012 5:40 am


Figured something out so I thought I would pass it on. The following code did not work for me.

-----
set text to ("line1"&Newline&"line2")
-----

Since it created Line1Line2, the textbox did not move it to different lines because it still thought it was the same word.

This worked for me though:

-----
set text to ("line1 "&Newline&"line2")
-----

The space after line1 made the difference.
B
2
Posts: 5
Reputation: 310


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests