Jump to content

allowing \n


Xander Lopez
 Share

You are about to reply to a thread that has been inactive for 1492 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

so i have a hud which opens a textbox 

llTextBox(llDetectedKey(0), "type your shout out", channel);

Then the message received from llTextBox gets sent to another Prim called "Receiver" via llRegionSayTo()

And this "Receiver" would display the message as hovertext

llSetLinkPrimitiveParamsFast(0, [PRIM_TEXT, received_message, <1.0,1.0,1.0>, 1.0]);

 

Then.. if the message was entered as "this is the first line. \nthis is the 2nd line.", it doesn't do the linebreak.

Rather it displays as "this is the first line. \nthis is the 2nd line."

How can I make sure that the hover text on receiver is shown as 

this is the first line.
this is the 2nd line.

Link to comment
Share on other sites

You can just press Enter on the dialog box, which will insert a newline.

Otherwise you'll have to explicitly find and replace every instance of the newline character pattern. From the wiki:

Quote

Escape codes are translated when the script is compiled; not while it's running. The compiler will ignore any other combination of \ with a character by removing the \. So "\a" means "a". The result is that only strings that are inside your script when it is compiled will get, say, \n turned into a "new line" character. Text you read in from a notecard, chat, http, object name or description, etc, will not be checked for escape codes -- that same \n typed in a notecard doesn't automatically turn into a "new line" character. You'll have to do that yourself, if you really really need it for some reason.

Edited by Wulfie Reanimator
  • Like 2
Link to comment
Share on other sites

11 hours ago, Xander Lopez said:

llTextBox(llDetectedKey(0), "type your shout out", channel);

 if the message was entered as "this is the first line. \nthis is the 2nd line.", it doesn't do the linebreak.

Rather it displays as "this is the first line. \nthis is the 2nd line."

How can I make sure that the hover text on receiver is shown as 

this is the first line.
this is the 2nd line.

we have to read the \n char in a literal string as \\n to force the compiler to recognise \n as a control code and not as the 2 literal chars \ and n

example:

text =  llDumpList2String(llParseString2List(text, ["\\n"], []), "\n");

 

Link to comment
Share on other sites

38 minutes ago, Mollymews said:

we have to read the \n char in a literal string as \\n to force the compiler to recognise \n as a control code and not as the 2 literal chars \ and n

example:


text =  llDumpList2String(llParseString2List(text, ["\\n"], []), "\n");

Your solution is correct, but your explanation is exactly backwards.

"\\n" doesn't force it to be recognized as the newline character. It explicitly means "backslash n" as in the two separate characters.

"\\" is interpreted as a single backslash character. "n" is then interpreted as a regular character.  This is important because the message in the listen event (as received from llTextBox) will contain the two characters separately.

Link to comment
Share on other sites

in the text box type in "this is line1.\nthis is line 2." . Press Submit

in the text box type in "this is line1." Press Enter/Return key.  Type in "this is line2.". Press Submit

ps edit

\\n

the first \ in ["\\n"] tells the compiler that a control code can follow.  The control code that follows is \n

Edited by Mollymews
Link to comment
Share on other sites

5 hours ago, Mollymews said:

the first \ in ["\\n"] tells the compiler that a control code can follow.  The control code that follows is \n

That's not how the first "\" works... it only applies to the next literal character... and "\\" itself is a complete escape code... go read the wiki page I linked.

5 hours ago, Mollymews said:

yes, but the wiki is wrong when it comes to how the llParseString2List function handles control codes in strings

The wiki can't even be wrong in the context of the code you showed because:

// TextBox input -- contains no actual control characters because it isn't a compile-time string.
// String length: 8
text = "1st\n2nd"

// Find TWO characters, backslash and n. Use those characters to separate.
// "\\n" has a string length of 2, not 1.
list parsed = llParseString2List(text, ["\\n"], []);

// parsed = ["1st", "2nd"]
// Combine the list into a single string but separate them with a real control character.
// The "\n" here is a compile-time string. (String length 1, not 2)
text = llDumpList2String(parsed, "\n");

If you were to use "\n" in llParseString2List, it (obviously) wouldn't work because the text that's coming in doesn't contain that character. It contains the two characters separately.

To try to make this more clear, llParseString2List does work just fine with "\n":

default
{
    state_entry()
    {
        string text = "1st\n2nd";   // Compile-time string, length 7.
        llOwnerSay(text);           // Outputs two lines.

        list parsed = llParseString2List(text, ["\n"], []);
        text = llDumpList2String(parsed, ",");
        llOwnerSay(text);           // Outputs "1st,2nd"
    }
}

The above code will replace the actual control character with a comma as expected.

Edit: I give up. [insert flipped table here]

Edited by Wulfie Reanimator
Link to comment
Share on other sites

3 minutes ago, Wulfie Reanimator said:

That's not how the first "\" works... it only applies to the next literal character... and "\\" itself is a complete escape code... go read the wiki page I linked.

yes, but the wiki is wrong when it comes to how the llParseString2List function handles control codes in strings

  • Sad 1
Link to comment
Share on other sites

i put this more succinctly for the reader

the first \ in the separator string of llParseString2List means that any \n found in the input string is to be treated as a control code

what Wulfie is saying is that \\ is the escape code and n is the control code

is semantics. Is not the complete opposite like exactly backwards

Edited by Mollymews
completely
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1492 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...