Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Still trying to get the hang of this first name only thing HELP

BankofLea Quandry
Registered User
Join date: 24 Jul 2008
Posts: 3
10-07-2008 22:56
I am attempting to modify this script so instead of say the full name of the owner and the full name of the other person it only says the first names. I have tried every method i have learned so far to one have a script say the first name but its not working can anyone show me how to do it on this script please. This script scan the area, gives you the names of people around you then you can targtet that have and have somthing said in open chat directed toward them. example

CODE
llSay(0, llKey2Name(llGetOwner()) + " smiles while handing " + message + " her tail and a brush");llSay(0, llKey2Name(llGetOwner()) + " smiles while handing " + message + " her tail and a brush");


Should say "Lea pokes BlackWidow."


CODE

integer dlgHandle = -1;
integer dlgChannel = -9999;
list avatarList = [];
reset()
{
llSetTimerEvent(0.0);
llListenRemove(dlgHandle);
dlgHandle = -1;
}
default
{
touch_start(integer total_number)
{
llOwnerSay("Scanning...");
avatarList = [];
// Look for any avatars within 10m.
llSensor("", NULL_KEY, AGENT, 96.0, PI);
}
sensor(integer num_detected)
{
integer i;
while((i < num_detected) && (i < 9))
{
if (llDetectedKey(i) != llGetOwner())
{
avatarList += [llDetectedName(i)];
}
++i;
}
if (llGetListLength(avatarList) > 0)
{
state dialog;
}
}
}
state dialog
{
state_entry()
{
// Set up a listener to detect button clicks.
dlgHandle = llListen(dlgChannel, "", llGetOwner(), "");

// Start a new timer.
llSetTimerEvent(30.0);

// Add a 'Cancel' button.
avatarList += ["Cancel"];

// Display the dialog.
llDialog(llGetOwner(), "Please select an avatar.", avatarList, dlgChannel);
}
listen(integer channel, string name, key id, string message)
{
// The message parameter holds the caption of the
// button that was clicked. Search the menu options
// list for it.
if ((channel == dlgChannel) && (llListFindList(avatarList, [message]) != -1))
{
if (message != "Cancel")
{
llSay(0, llKey2Name(llGetOwner()) + " pokes " + message);
}
reset();
state default;
}
}
timer()
{
reset();
state default;
}
}
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
10-08-2008 00:13
This hasn't been compiled or tested, so it may need a minor syntax fix or two. But it is pretty simple, so it is probably worth the risk.

CODE

string getFirstName(string fullName)
{
integer spaceIndex = llSubStringIndex(fullName, " ");
if (spaceIndex < 0)
{
return fullName;
} else if (spaceIndex == 0)
{
return "";
}

return llGetSubString(fullName, 0, spaceIndex-1);
}
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
10-08-2008 02:50
I have never had an issue with this one-liner version.

name = llGetSubString(name, 0, llSubStringIndex(name," ";) - 1);
Lea Vendetta
I broke my invetory
Join date: 22 Sep 2007
Posts: 97
10-08-2008 04:20
From: Hewee Zetkin
This hasn't been compiled or tested, so it may need a minor syntax fix or two. But it is pretty simple, so it is probably worth the risk.

CODE

string getFirstName(string fullName)
{
integer spaceIndex = llSubStringIndex(fullName, " ");
if (spaceIndex < 0)
{
return fullName;
} else if (spaceIndex == 0)
{
return "";
}

return llGetSubString(fullName, 0, spaceIndex-1);
}


From: Very Keynes
I have never had an issue with this one-liner version.
CODE



name = llGetSubString(name, 0, llSubStringIndex(name," ") - 1);



In which part of my script would i incorporate either of these pieces of code? Cause all i am getting is errors.
_____________________
Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
10-08-2008 07:29
made a storage var incase you need to store it and a touch so you can see it working

CODE

string firstName;

string getFirstName(string fullName)
{
firstName = llGetSubString(fullName, 0, llSubStringIndex(fullName," ") - 1);
return llGetSubString(fullName, 0, llSubStringIndex(fullName," ") - 1);
}

default
{
touch_start(integer total_number)
{
llSay(0, getFirstName(llKey2Name(llDetectedKey(0))));
}
}
Lea Vendetta
I broke my invetory
Join date: 22 Sep 2007
Posts: 97
10-08-2008 12:07
Still not working but ty all for trying to help me, i appreciate it.
_____________________
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
10-08-2008 16:07
CODE

string firstName (string input)
{
return llList2String( llParseString2List( input, [" "], [] ), 0 );
}


CODE

string firstName (string input)
{
return llDeleteSubString( input, llSubStringIndex(input, " "), -1 );
}


CODE

string firstName (string input)
{
return llGetSubString( input, 0, llSubStringIndex(input, " ") - 1);
}


Any of the three functions above will work...

Here's an example of how to use it. (I prefer the second one).

CODE

string firstName (string input)
{
return llDeleteSubString( input, llSubStringIndex(input, " "), -1 );
}

default
{
state_entry()
{
llSay(0, firstName(llKey2Name(llGetOwner())));
}
}


Here's a gotcha. llKey2Name *ONLY* works if the person is in the same sim as the script doing the lookup. It's a STUPID limitation. So be sure, in your application, that you're storing the name, or using the name only when the owner is in the same sim.

A collar, for example, is always going to be around your neck. But a vendor may be in your shop, while you're out of the sim. So if this is a name you need to have access to when you may be offline, save the results of llKey2Name(llGetOwner()) during your script's startup phase. Just make sure to refresh this data on rez, or on owner change. Also it's important to note that this limitation affects any avatar.. which is why it's so darned hard to program "buy as gift" vendors.
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-08-2008 18:35
When you are frustrated and can't figure out a problem, it helps to break it down to the constituent parts. You are trying to solve the name so put just it in another script like this:
CODE

default
{
state_entry()
{
llSay(0, llKey2Name(llGetOwner()) + " pokes ");// + message);
//message is not defined here so just leave it out for now
}
}

That will return in my case:
"new: Jesse Barnett pokes "

Now you are setup for experimenting without worrying about the rest of the code. So lets try what Very suggested:

CODE

default
{
state_entry()
{
string name = llKey2Name(llGetOwner());
name = llGetSubString(name, 0, llSubStringIndex(name," ") - 1);
llSay(0, name + " pokes ");
}

}

and that returns:
"new: Jesse pokes "
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum