Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

String Oddity

Solomon Devoix
Used Register
Join date: 22 Aug 2006
Posts: 496
06-04-2007 14:56
Okay, here's something that struck me as odd, and I'm hoping someone can tell me a simple reason why it's working oddly.

This is in relation to a simple "HUD scanner" script... the kind that once a second scans for avatars in the area and shows a list of them, using float text, above an invisible prim attached to a HUD point. There's nothing mysterious about this; these things have been around forever. What is mystifying me is this:

For my purposes, the float text needs to always start at a certain height on the screen, and the list grows downwards as more people are added to it. That's fairly straightforward. If I use a loop to add newline characters to pad out the string for the float text, it works fine. If instead of a loop I use llGetSubString to take a piece of a string containing nothing but newline characters and tack it on to the end of the string for the float text... they don't show up. But if that same string is displayed another way (via, say, llOwnerSay) the blank spacing newlines show up!

This has me scratching my head.

Here's the script:

CODE

string spacer = "\n\n\n\n\n\n\n\n\n\n\n\n";

default
{
state_entry()
{
llSetText("",<0,0,0>,1);
llSensorRepeat("",NULL_KEY,AGENT,96,PI,1);
}

link_message(integer sender, integer num, string msg, key id)
{
if (msg == "sensor off")
{
llSensorRemove();
llSetText("",<0,0,0>,1);
}
else if (msg == "sensor on")
{
llSensorRepeat("",NULL_KEY,AGENT,96,PI,1);
}
}

sensor(integer num_detected)
{
string title = "";
integer distance;
integer x;
integer count = 0;

if ( num_detected > 12 )
{
num_detected = 12;
}

for( x = 0; x < num_detected ; x++ )
{
distance = llFloor(llVecDist(llGetPos(),llDetectedPos(x)));
if ( distance < 96 )
{
title += (string)llDetectedName(x)+" ("+(string)distance+"m)\n";
count ++;
}
}

// title = title + llGetSubString(spacer, count, 12);

// To see the odd behavior, comment out the following line and un-comment the prior line

for( x = count; x < 13 ; x ++ ) title = title + " \n";

llSetText(title,<1,1,1>,1);
}

no_sensor()
{
llSetText("",<1,1,1>,1);
}
}
Ultralite Soleil
Registered User
Join date: 31 Aug 2006
Posts: 108
06-04-2007 15:46
It's probably because the \n character is strange in LSL. According to Argent Stonecutter in a recent thread:

From: Argent Stonecutter
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.


He was talking about notecards with \n in them, but your problem might be similar.
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
06-04-2007 15:54
No, it's actualyl a different issue.

llSetText has a quirk, and so does the script.

From The Wiki

From: The Wiki
"\n" can be used to start a new line. Empty lines must have at least one character (use a space: " \n";). text has a length limit of 255 characters.


In your script, your loop uses the correct string with a space and a newline, but your spacer global string variable is just a bunch of newlines. As such, it won't work the same, because of the quirk with llSetText.
Solomon Devoix
Used Register
Join date: 22 Aug 2006
Posts: 496
06-04-2007 16:12
[there is a loud slap as Solomon facepalms himself]

Doggone it, I completely forgot about that, and today had missed seeing the space I'd inserted there when I intially wrote the loop a while back.

[sigh]

Thanks guys... just my own blindness at work...