Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Line breaks in strings read from a notecard?

Tyg Jarrico
Registered User
Join date: 29 May 2005
Posts: 98
01-15-2006 23:01
I have a string with the "\n" character in it, that is read from a notecard and put in a variable. When I llSay the variable, the "\n" doesn't produce a line break but displays as the characters "\n".

Is there any way to put a line break in a string read from a notecard and then put in a variable?
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
01-15-2006 23:51
By definition. llGetNotecardLine gets a line (that is, a string of text terminated by a line-break "\n";) from a notecard, therefore making it impossible to read the line-break character itself.
==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
01-16-2006 06:01
You'd have to do a backslash parser.

"\n" is initially parsed by the compiler.
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
01-16-2006 09:53
From: Tyg Jarrico
I have a string with the "\n" character in it, that is read from a notecard and put in a variable. When I llSay the variable, the "\n" doesn't produce a line break but displays as the characters "\n".

Is there any way to put a line break in a string read from a notecard and then put in a variable?



string unescaped = llDumpList2String(llParseStringKeepNulls(notecard_line, ["\\n"], []), "\n";);

or more general unescaping...

string unescaped = llDumpList2String(llParseStringKeepNulls(notecard_line, ["\\"], []), "\";);
_____________________
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
01-16-2006 09:56
Basically, "\n" is not a character, it's two characters. The compiler translates those into a single character when the script is compiled. Notecards don't get translated this way.

I suspect that llDumpList2String(llParseStringKeepNulls(line, ["\\n"],[]),"\n";); is what you're looking for. Note that there are two "\" characters in the first "\\n" string, which will make the compiler translate it to a literal "\n" sequence rather than a newline.

[Edit: posted at the same time as Rickard. His second example won't work, by the way, it's not even going to compile]
Tyg Jarrico
Registered User
Join date: 29 May 2005
Posts: 98
01-21-2006 07:30
Thank you all, especially Argent. That worked perfectly.
Tyg Jarrico
Registered User
Join date: 29 May 2005
Posts: 98
01-21-2006 07:37
One question. This technique doesn't work with say? In other words, if I use llSay on the line, it doesn't break into multiple say lines? Is there a way of doing that?
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
01-21-2006 07:41
No, says ignore newline characters, unfortunately.
_____________________
~ Tiger Crossing
~ (Nonsanity)
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
01-21-2006 10:46
Although they do appear in your history, which is an odd little quirk.