Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Return of the please help moment.

Keith Richter
Registered User
Join date: 27 Jan 2007
Posts: 21
11-18-2008 19:07
Well I went for a longer period of time this time before hitting a wall and getting lost at least, improvement whoo! okay anyways.

I'm trying to make something recognize multiple parts of what it picks up in listen and seperate them. Example: "pay 100 jack" I'm trying to make it recognize that 'pay' is the command '100' is the amoutn and 'jack' is the target. So maybe a way for it to read each thing divided by spaces or something?

Part two is how do people set up scripts to recognize just part of the name? Example my av's name is "Keith Richter" yet people can just type "kill keith" into some fancy gadget and it'll look for the closest match.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-18-2008 19:18
See http://wiki.secondlife.com/wiki/LlParseString2List for how to chop up a line..

For how to be told "keith" and end up with "Keith Richter" you probably want to use a sensor that looks at all the avatars nearby and picks the closest match.. Some of the things you'll want to play with when comparing strings:

http://wiki.secondlife.com/wiki/LlToUpper to convert everything to lower case (or llUpper if you want upper case) for case-insensative compares.

http://wiki.secondlife.com/wiki/LlSubStringIndex will find a string within a string.
Keith Richter
Registered User
Join date: 27 Jan 2007
Posts: 21
11-19-2008 14:56
thanks that helped me figure out a few of the problems but now i have a new one.

if(bal < (integer)llList2List(llParseString2List(message,[" "],[]),1,1))

and

bal - (integer)llList2List(llParseString2List(message,[" "],[]),1,1);


give the error "type mismatch" so most i figure is I can't turn them into numbers for those or something. Is there a way to fix that or another way for it to take the 2nd word a person says (which would be numbers) for those parts?
Keith Richter
Registered User
Join date: 27 Jan 2007
Posts: 21
11-19-2008 16:57
Ignore the above one, i got it to work with llList2Integer.

Still any extra suggestiosn on the finding closest match through the sensor would help. Currently looking into it (I havn't had to use sensors before yet so its taking a bit of effort) but still thorougly lost lol
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-19-2008 19:47
CODE

//-- this goes in the listen event, don't forget to declare the global
gStrPartialName = llToLower( someUserGeneratedNameFragment );
llSensor( "", "", AGENT, 96, PI );

sensor( integer vIdxFound ){
while (vIdxFound ){
if (~llSubStringIndex( llToLower( llDetectedName( --vIdxFound ) ), gStrPartialName )){
//-- use the index to grab key and do stuff
jump found;
}
}
if (~vIdxFound){
//-- tell the user no target was found
}
@found;
}

no_sensor(){
//-- tell the user no one is around
}

the jump isn't the best way to handle it, but it's one of those fun cases in lsl where it's better than the alternative in this limited case
_____________________
|
| . "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...
| -
Keith Richter
Registered User
Join date: 27 Jan 2007
Posts: 21
11-19-2008 23:02
okay so i tinkered with it a bit and got it to work somewhat except for one part. No matter what i put in it'll find something, if i just put the letter l it'll come up with "Keith Richter" instead of deciding nothing was found. edit: okay so i tped someone else to stand next to it and test something, no matter what i put it will always return finding me even if i put their full name in.

also i notice the ~ character seems to do something but what does it do exactly? Yes i'm new at scripting this much if you havn't guesed lol.

Right now i think it's because the script i'm using has the listen not properly set up maybe, though not entirely sure what to do to fix it after an hour of toying around.

here's what i have so far if it helps anyone to find out whatever my issue is.

CODE

listen(integer chan, string name, key id, string msg)
{
msg = gStrPartialName = llToLower(gStrPartialName);
llSensor("","",AGENT,20,PI);
}
sensor( integer found )
{
while (found )
{
if (~llSubStringIndex( llToLower(llDetectedName( --found ) ), gStrPartialName ))
{
llSay(0,"found " + (string)llDetectedName(found));
jump found;
}
}
if (~found)
{
llSay(0,"not found");
}
@found;
}
Wouter Hobble
Registered User
Join date: 25 Mar 2008
Posts: 21
11-20-2008 00:53
From: Keith Richter

also i notice the ~ character seems to do something but what does it do exactly? Yes i'm new at scripting this much if you havn't guesed lol.


~ is a bitwise complement function. What you need to know is that:

~0 is a positive number
~-1 is a negative number

therefore:
if (~0) llSay(0, "This code is reached";);
if (~-1) llSay(0, "This code is not reached";);


From: Keith Richter

Right now i think it's because the script i'm using has the listen not properly set up maybe, though not entirely sure what to do to fix it after an hour of toying around.

here's what i have so far if it helps anyone to find out whatever my issue is.

listen(integer chan, string name, key id, string msg)
{
msg = gStrPartialName = llToLower(gStrPartialName);
llSensor("","",AGENT,20,PI);

Here lies your problem:

I assume gStrPartialName is a public variable (e.g. defined at the top ofyour script) which keeps its starting value. You keep assigning the same empty value you used to define it with.

Change:
msg = gStrPartialName = llToLower(gStrPartialName);
To:
gStrPartialName = llToLower(msg);
Wouter Hobble
Registered User
Join date: 25 Mar 2008
Posts: 21
11-20-2008 01:23
As for the original suggested script, some comments and made into something you should be able to copy paste and make it work.

CODE

string gStrPartialName = "";

default {
state_entry() {
llListen(0, "", NULL_KEY, "");
}

listen(integer channel, string name, key id, string message) {
if (llGetSubString(llToLower(message), 0, 3) == "scan") {
gStrPartialName = llToLower( llGetSubString(message, 5,-1) );
llSensor( "", NULL_KEY, AGENT, 96.0, PI );
}
}

sensor( integer vIdxFound ){
integer found = FALSE;
while (vIdxFound ){
// Wouter Hobble:
// The ~ operator is a bitwise complement, interesting for bitwise comparisons
// See the following for more info:
// http://www.cprogramming.com/tutorial/bitwise_operators.html
// llSubStringIndex will return 0 if found from start which will become a
// positive integer with ~ if it is -1 it will be a very strong negative
// not found == -1
// For more clarity I usually write this as llSubStringIndex(blah, b) != -1
if (~llSubStringIndex( llToLower( llDetectedName( --vIdxFound ) ), gStrPartialName )){
llSay(0, "Found: " + llDetectedName(vIdxFound));
//-- use the index to grab key and do stuff
// Wouter Hobble: I would never ever do this this way!
// Creates spagetti code.
//jump found;

// instead I would use this:
found = TRUE;
}
}
// Wouter Hobble:
// here I would have just used ! as the value at the end of looping will be 0, bug here I think...
// if (~vIdxFound){
// For logic you would now use:
if (!found) {
//-- tell the user no target was found
}
// No Spagetti
//@found;
}

no_sensor(){
//-- tell the user no one is around
}
}
Keith Richter
Registered User
Join date: 27 Jan 2007
Posts: 21
11-20-2008 23:49
thanks a lot guys it's really helping me learn new tricks and ideas :D

though i've encountered something that im sure was mentioned somewhere and i didn't find in the vast sl database when i poked around.

The listens on the object worn as a HUD don't seem to co-operate. If i drop it onto the ground it will work, but if it put it on my HUD it won't. And in one odd case it will register the listen only in the one instance i set up to say it failed because you gave a number higher then the balance. but if you go lower or exact it won't do anything, then i take the HUD off and the lower or exact number will work just fine.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-21-2008 10:37
guess I should have mentioned it'll find the first partial match ANYWHERE in the name... so you want to type in as much of the name as possible, another caveat is that it checks in order of distance from the object... the loop I used counts down, so farthest first, closest last.... you may wish to change that, or at least make a small sensor range than 96m
_____________________
|
| . "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...
| -
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
11-21-2008 12:19
From: Wouter Hobble
~ is a bitwise complement function. What you need to know is that:

~0 is a positive number
~-1 is a negative number


Minor correction

~-1 is exactly zero, it is never a negative number as zero is a positive whole number.

it works in LSL because of the simple way the LSL handles conditionals.

0 = FALSE, any other value, positive or negative, is TRUE.