Jump to content

Finding word match as part of list


Jenna Huntsman
 Share

You are about to reply to a thread that has been inactive for 1512 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hey guys,

 

I'm having problems getting my script to find a word match in part of a list.

I've got my script to read configuration values from a notecard, and store each line of the notecard as a list entry, so for example the notecard is:

Animation1 @ command @ number @ location @ frequency @ sitter
Animation2 @ command @ number @ location @ frequency @ sitter
Animation2 @ command2 @ number @ location @ frequency @ sitter
Animation3 @ command @ number @ location @ frequency @ sitter

And these are stored in a list called localmem.

I'm trying to use llListFindList(localmem, [POSE_NAME])

POSE_NAME is the name of a pose taken from an inbound command from AVSitter, and returns the name of the pose as a string (e.g. "Animation2")

only problem is, that llListFindList is always returning -1

 

How can I make it look for a word match as part of a list entry, and return the index of the location? Also, as there can be multiple commands tied to a single pose, how can I find all occurrences of the word and return all indexes of where it was found? (Ideally returning the indexes as a list)

 

Thank you! :)

Edited by Jenna Huntsman
Link to comment
Share on other sites

Try this:

integer i;
integer len = llGetListLength(localmem);
while (i < len)
{
    string Anim = llToLower(llGetSubString( llList2String( localmem, i ),0,9));
    if ( Anim == llToLower( POSE_NAME) )
    {
        //Got a live one.  Do something
    }
    ++i;
}

 

Edited by Rolig Loon
typos, of course
Link to comment
Share on other sites

11 minutes ago, Rolig Loon said:

Try this:


integer i;
integer len = llGetListLength(localmem);
while (i < len)
{
    string Anim = llToLower(llGetSubString( llList2String( localmem, i ),0,9));
    if ( Anim_number == llToLower( POSE_NAME) )
    {
        //Got a live one.  Do something
    }
    ++i;
}

 

That *kind-of* works, but is returning weird parts of the command if the animation name is short (e.g. relax)

Link to comment
Share on other sites

14 minutes ago, Jenna Huntsman said:

That *kind-of* works, but is returning weird parts of the command if the animation name is short (e.g. relax)

Oh, well then.... I was only playing off the example that you showed, in which all of your anims were named AnimationX. When all the names are the same length, it's a snap.  When they aren't, you have to be slightly more imaginative.  Either use

list temp = llParseString2List(llList2String(localmem,i),["@"],[]) ;

and then look at string Anim = llList2String(temp,0), or use 

integer idx = llSubStringIndex (llList2String(localmem,i),"@");

to find the first occurrence of "@" in a line of your data from your notecard and then read

string Anim = llGetSubString(llList2String(localmem,i), 0,idx);

In any case, it's simply a matter of looping through localmem one element at a time and examining that first substring.

(WARNING: There's almost certainly a typo in something I just typed above. Debugging is half the fun of scripting. ) :)

Edited by Rolig Loon
Found one....
Link to comment
Share on other sites

18 minutes ago, Rolig Loon said:

Oh, well then.... I was only playing off the example that you showed, in which all of your anims were named AnimationX. When all the names are the same length, it's a snap.  When they aren't, you have to be slightly more imaginative.  Either use

list temp = llParseString2List(llList2String(localmem,i),["@"],[]) ;

and then look at llList2String(temp,0), or use 

integer idx = llSubStringIndex (llList2String(localmem,i),"@");

to find the first occurrence of "@" in a line of your data from your notecard and then read

string Anim = llGetSubString(llList2String(localmem,i), 0,idx);

In any case, it's simply a matter of looping through localmem one element at a time and examining that first substring.

(WARNING: There's almost certainly a typo in something I just typed above. Debugging is half the fun of scripting. ) :)

That worked, thank you!

For reference, my code is now:

                list animtemp = llParseString2List(llList2String(localmem,i),["@"],[]);
                string Anim = llToLower(llList2String(animtemp, 0));
                Anim = llStringTrim(Anim, STRING_TRIM_TAIL);

Added a llStringTrim to get rid of the space before the @ sign!

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1512 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...