Difference between revisions of "IsInList"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL_Function |mode=user |func=IsInList |p1_type=list|p1_name=data |p2_type=string|p2_name=name |return_type=integer |return_text= |func_desc='''This function can be used to det…")
 
m (removed white space)
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
integer IsInList(list data, string name)
integer IsInList(list data, string name)
{
{
     integer i;
     if(llListFindList(data,[name]) != -1) return TRUE;
    for(i=0; i < llGetListLength(data);i++)
     else return FALSE
    {
        if(llList2String(data, i) == name)
        {
            return TRUE;
        }
    }
   
     return FALSE;
}
}
</lsl>
</lsl>



Latest revision as of 08:05, 3 February 2012

Summary

Function: integer IsInList( list data, string name );

This function can be used to determine if a string variable is in a list
Returns an integer

• list data
• string name

KBtip2.png Tip: other variable types can be used with the exception of lists

<lsl> integer IsInList(list data, string name) {

   if(llListFindList(data,[name]) != -1) return TRUE;
   else return FALSE

} </lsl>

KBtip2.png Tip: See my wiki page for a video tutorial of this function

<lsl> // Simple Visitor's List that will not allow duplicate list entries using the IsInList() function default {

   state_entry()
   {
       llListen(-23467589, "", "", "");
       llSensorRepeat("", "", AGENT, 10.0, PI, 180);
       llSetTimerEvent(86400);
   }
   
   touch_start(integer total_number)
   {
       llTextBox(llDetectedKey(0), "What are you looking for?", -23467589);
       TypeOutList();
   }
   
   listen(integer channel, string name, key id, string message)
   {
       if(IsInList(visitors, message))
       {
           llSay(0, message + " is in the list.");
       }else{
           llSay(0, message +  " is not in the list");
       }
   }
   
   sensor(integer detected)
   {
       integer i;
       for(i=0; i < detected; i++)
       {
           if(IsInList(visitors, llDetectedName(i)))
           {
              // DO NOTHING- already in the list 
           }else{
               visitors += llDetectedName(0);
               llOwnerSay("Added " + llDetectedName(0) + " to the visitors list. \nFree Memory: " + (string) llGetFreeMemory());
               llOwnerSay("There are now " + (string) llGetListLength(visitors) + " names in the visitors list.");
           }
       }
   }
   
   timer()
   {
       // Optional
       llEmail("your_email_address@your_domain.com", "Here is the Visitors List for today", llList2CSV(visitors) );
   }

} </lsl>

Examples