Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Av detection using part of an av's name. how?

Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
09-16-2007 07:31
Hello. I have this little script.
CODE

string name;

default
{
state_entry()
{
llListen(1,"",llGetOwner(),"");
}

listen(integer channel, string name, key id, string message)
{
if (llToLower(llGetSubString(message,0,5)) == "hello ")
{
name = llGetSubString(message,6,-1);
llSensor((string)name, NULL_KEY, AGENT, 10, PI);
}
}
sensor(integer total_number)
{
integer i;
list targets = [];
for (i = 0; i < total_number; i++)
{
llSay(0,"Hello "+(string)llDetectedName(i));
}

}
no_sensor()
{
llSay(0,"no target");
}
}


As you can see, it needs the whole target's name for it to work. How do I make it only need part of it? Thanks in advance.
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
09-16-2007 07:58
Scan for anybody and do some string comparisons to find the AV you need...
Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
09-16-2007 09:00
Never written string comparisons. How do I learn that?
Jos Young
Registered User
Join date: 11 Dec 2006
Posts: 22
llSubStringIndex
09-16-2007 10:36
You could take a look at

<url>http://wiki.secondlife.com/wiki/LlSubStringIndex</url>

It gives an example on how to look for a last name after a sensor event. This can also be used to look for a partial name.

With function llSubStringIndex you can look for a sub string in a string. It gives the index of the place where the substring is found or -1 if it is not found.

Good luck,

Jos
Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
09-17-2007 14:39
Checking. Thank you.

<edit> So far so good. I'm getting it to say my name even if I just input the first three letters, no matter if I use caps on it or not. Now going to test the code with other people around.
Tre Giles
Registered User
Join date: 16 Dec 2005
Posts: 294
09-17-2007 14:52
FIX
CODE

string name;

default
{
state_entry()
{
llListen(1,"",llGetOwner(),"");
}

listen(integer channel, string name, key id, string message)
{
if (llToLower(llGetSubString(message,0,7)) == "search ")
{
name = llGetSubString(message,8,-1);
llSensor("", NULL_KEY, AGENT, 10, PI);
}
}
sensor(integer total_number)
{
integer i;
for (i = 0; i < total_number; i++)
{
if(llSubStringIndex(llToLower(llDetectedName(i)), llToLower(name)) != -1)
{
name = llDetectedName(i);
llOwnerSay("Target " + name + " was found!");
llSensorRemove();
}
}

}
no_sensor()
{
llOwnerSay("Target not found.");
}
}


llSubStringIndex is your savior.

Look in the above quote, I edited it to make it work. It should now work with "only part of the name". It works by saying "search [entry]". Hope I helped lol.

And yes, its untested folks xD
Hanumi Takakura
Registered User
Join date: 24 May 2006
Posts: 57
09-17-2007 15:15
<re-re edit>
Well. Tried to post something useful here. But it still got too many errors. I'll try posting it later.