Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Partial name matching

Susie Chaffe
Registered User
Join date: 13 Mar 2007
Posts: 29
02-27-2008 04:17
I am trying to build a particle poofer that targets an avatar specified by a chat command.

I can target a specific avatar using an avatar's whole name and key, using a chat command.

I can use a sensor to get the names of the nearest 16 avatars and put them in a list

What I would like to do is target an avatar using an abbreviated name i.e. Sus for Susie.

I am guessing i need to do a looped comparison using llGetSubString.

Does anyone have a sample of such a piece of code, or can point me in the right direction ?
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
02-27-2008 05:45
llgetSubString will return -1 if not found, otherwise the index.

As you are looking for partial names, you can safely discard anything with an index greater than 0.

So only names where that function returns a 0 start with the given substring.

The scripts that use this form of pattern matching usually take the first hit they find.
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
02-27-2008 06:45
This code snippet from another of my projects may help

CODE

integer like(string arg1, string arg2)
{
float tmpx; float tmpy;
if(llGetSubString(arg2,0,0)=="%"){arg2=llGetSubString(arg2,1,-1);tmpy=1;}
if(llGetSubString(arg2,llStringLength(arg2)-1,-1)=="%")
{arg2=llGetSubString(arg2,0,llStringLength(arg2)-2);tmpy=tmpy+2;}
if(-1!=(tmpx=llSubStringIndex(arg1,arg2)))
{
if((tmpy==0 && llStringLength(arg1)==llStringLength(arg2))
||(tmpy==1 && tmpx == (llStringLength(arg1)- llStringLength(arg2)))
||(tmpy==2 && tmpx == 0)
||(tmpy==3))
{return TRUE;}
}
return FALSE;
}


It emulates the SQL LIKE function (well partially) so to use it you pass a value and a mask.
To use your example:

like("Susie", "Sus%";) will return true, for any value Starting with "Sus"
like("Susie", "%Sus%";) will return true, for any value containing "Sus"
like("Susie", "%Sus";) will return false, this case is looking for a string ending in "Sus".

If you loop through your list passing the value and the mask it will allow you to find which names are a valid match.

Hope it helps

edit:
I forgot to mention that:
like("Susie", "Sus";) will return false, this case is looking for a string matching only "Sus".

tmpx and tmpy can be integer, in my case they are float as they are used for more advanced comparissons later in the code I use, but as you only ascked for partial string matching, I left out all the numeric stuff :)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
02-27-2008 19:09
Here is one for you to play with that will do partials:
CODE
string Name = "jes";
integer on;
integer handle;

default {
touch_start(integer n) {
if (!on) {
handle = llListen(0, "", "", "");
}
else {
llListenRemove(handle);
on = !on;
}
}
listen(integer chan, string name, key id, string msg) {
if (~llSubStringIndex(llToLower(msg), llToLower(Name)))
llOwnerSay(msg + " = " + Name);
}
}


output:
"[19:05] You: j
[19:05] You: je
[19:05] You: jes
[19:05] Object: jes = jes
[19:05] You: jess
[19:05] Object: jess = jes
[19:05] You: jesse
[19:05] Object: jesse = jes
[19:06] You: I love jesse
[19:06] Object: I love jesse = jes"
_____________________
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
Susie Chaffe
Registered User
Join date: 13 Mar 2007
Posts: 29
thanks for ideas
02-27-2008 23:46
Thank you for the pointers, some very different routes to find a solution, which is great.
Time to start testing :)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-28-2008 01:49
as for the targeting portion, taking a page from the standard hugger scripts I've seen (and assuming you want the partial to be the first part of the name as described by squirrel)

CODE

sensor( integer vIntSensed ){
do{
if (!llSubStringIndex( llDetectedName( --vIntSensed ), partialString ){
//-- do stuff
//--return
}
}while (vIntSensed)
}


will return the first partial match within the sensor results and act on them (notice the !(not) symbol at the begining.. this limits the partial match to the begining of the name, so it must start with this
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -