IsInList

From Second Life Wiki
Jump to: navigation, search

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