Jump to content

Help with lists


joshua Bumbo
 Share

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

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

Recommended Posts

Hello, I have a question regarding lists. So I got this little bit of code to work. What I need to do is in stead of "del 1" is to be able to delete by name 'del Bob'  and make it a list again. Any help is appriciated. 

 

Code:

list fruit = ["Anthony", "Bob", "Charlie", "Diane", "Edgar", "Gabriela"];

TypeOutList(list data)
{
llOwnerSay("List Contains " + (string) llGetListLength(data) + " items.\n" + llList2CSV(data));  
}

default
{
    state_entry()
    { 
    llListen(0, "", llGetOwner(), "");
    }
    
    touch_start(integer total_number)
    {
    TypeOutList(fruit);
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if (llToLower(llGetSubString(message, 0, 3)) == "del ")
        { 
            if ( (integer) llGetSubString(message, 4, -1) >= llGetListLength(fruit) +1)
            {
            llOwnerSay("sorry, but the list only has " + (string) llGetListLength(fruit) + " items in it!");
            }
            else
            {
            fruit = llDeleteSubList(fruit, (integer) llGetSubString(message, 4, -1) -1 , (integer) llGetSubString(message, 4, -1) - 1);
            TypeOutList(fruit);
            }
        }
    }
}

 

Link to comment
Share on other sites

Hello...

To find out the index of an item in list you can use llListFindList. (http://wiki.secondlife.com/wiki/LlListFindList)

In your case this would work:

if ((llToLower(llGetSubString(message, 0, 3)) == "del ") && (llStringLength( message)>4));
{

            string delName=llGetSubString(message, 4, -1) ;

            integer index=llListFindList(fruit,[delName]);

            if (index!=-1)

            {

                 fruit =  ListItemDelete( fruit, delName);

            }

            else

            {

                       llOwnerSay("Sorry, but "+ delName+" ist not in list");

            }

}

Link to comment
Share on other sites

something like....

 

 listen(integer channel, string name, key id, string message)    {        if (llToLower(llGetSubString(message, 0, 3)) == "del ")        {             integer index = llListFindList(fruit, [ llGetSubString(message, 4, -1) ]);            if(index != -1)            {              fruit = llDeleteSubList(fruit, index,index);              TypeOutList(fruit);            }            else if ( llGetSubString(message, 4, -1)  )             llOwnerSay("no ..." + llGetSubString(message, 4, -1) + "... found...try again?" );                              }    }
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2732 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...