Jump to content

is there an function that search an integer inside a list?


1klans2
 Share

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

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

Recommended Posts

i wanna know, i wanna make an integer that says random integers and register them in an list and dont let registers 2 numbers again, and if is possible a kind of function that if a list have an number of integers do something, i wait someone can understand me c:

Link to comment
Share on other sites

i wanna know, i wanna make an integer that says random integers and register them in an list and dont let registers 2 numbers again, and if is possible a kind of function that if a list have an number of integers do something, i wait someone can understand me c:

Link to comment
Share on other sites

// Best viewed in Chat History (ctrl-h)default{    state_entry()    {        list my_list = ["a", 1, 2.0, <1,2,3>, <1,2,3,4>, llGetOwner()];        integer i = ~llGetListLength(my_list);        while (++i)        {            llOwnerSay("string=" + llList2String(my_list,i)                        + "\n   integer=" + (string)llList2Integer(my_list,i)                        + "\n   float=" + (string)llList2Float(my_list,i)                        + "\n   vector=" + (string)llList2Vector(my_list,i)                        + "\n   rot=" + (string)llList2Rot(my_list,i)                        + "\n   key=" + (string)llList2Key(my_list,i) );        }    }}

 

http://wiki.secondlife.com/wiki/LlList2Integer

 ADDED: randomNum =(integer)llFrand http://wiki.secondlife.com/wiki/LlFrand 

Then you have to search the list and if it not there add to it, Tho the list my get filled very quickly.

my_list += randomNum // That will add to the global list, 

I not writing a whole script, this just to give you a start.

Link to comment
Share on other sites

integer card;list cardlist=[];default{    state_entry()    {        llListen(0,"",llGetKey(),"");    }    touch_start(integer total_number)    {        card=llRound(llFrand(49));        llSay(0,(string)card);            }    listen(integer asd,string sdf,key id,string df)    {        cardlist+[df];       if(df=llListFindList([df],cardlist));       {           llSay(0,(string)llRound(llFrand(49)));        }    }}

 it send me error D:

Link to comment
Share on other sites

Despite seeing the script, I still don't understand what's actually being attempted here. But a few comments about what won't work in this script:

  • The arguments to llListFindList are swapped. The source list comes first, followed by the sublist that's to be found in the source.
  • llListFindList returns the index of the found item, or -1. It does not return the found item itself. So usually one tests for the result not being -1 (for which the ~ operator is sometimes used).
  • A script cannot listen to itself. If for some unspecified reason, some processing is supposed to happen outside the touch_start event handler, a script can send a link_message to itself.
  • To test equality, use the "==" operator. "=" is for assignment.
  • I don't know for sure what "cardlist+[df];" was supposed to do, but if I had to guess, it may have been intending to append df to the end of cardlist which instead calls for "cardlist += df;"
  • Rather than llRound(llFrand(49)), (integer)llFrand(50.0) will give a slightly more uniform distribution.

Correcting these problems still doesn't generate a script that does anything useful, but again, it's not clear what was intended.

Link to comment
Share on other sites

This outputs a number between 0 and 49, but does not add it to the list.

integer card;list cardlist=[];default{    state_entry()    {        llListen(0,"",llGetKey(),"");    }    touch_start(integer total_number)    {        card=llRound(llFrand(49));        llSay(0,(string)card);            }

 This means nothing.

cardlist +[df];       if(df=llListFindList([df],cardlist));

  That all i doing

integer card;list cardlist=[];integer limit = 10000; // <- bytesdefault{	changed(integer ch)	{		if(ch&CHANGED_OWNER)		{			llResetScript();		}	}	on_rez(integer num)	{		llResetScript();	}	state_entry()	{		llSetMemoryLimit(limit);//No point waisting resorces	}	touch_start(integer total_number)	{		card = (integer)(llFrand(50));		if(~llListFindList(cardlist,(list)card))		{			llSay(0,(string)card+" You got a match, card number is "+(string)card);		}		else		{			llSay(0,"card number is "+(string)card);			cardlist += card;			cardlist = llListSort(cardlist, 1, TRUE);//I just like neatness		}	}}

  And thats as efficient as i can get it. I sure someone else would have done this in 10 secs instead i wrote it about 10 times. This script will only add till all 50 are in the list then thats it, so it will not be a dead wieght. Only problem i see is that as the numbers added to the list the matching numbers will increasingly get closer together. Maybe a timer reset be good idea or a touch count. Hope this not for gambling thats against TOS. And i was not going to write the script LOL, maybe  slow but i get there in the end.

 

 

 

Link to comment
Share on other sites

can someone help improve this script,

when you press 'visitor list' - it displays all the names, but i also want to record the date/time

 

list ScannerItems = ["75m ", "90m ","40m ", "50m ", "60m ", "25m ", "30m ", "35m ", "10m ", "15m ", "20m " ];

integer NOTIFYOWNER = TRUE;
integer MAXLISTSIZE = 100;

integer menu_channel;
integer menu_handler;

menu(key user,string title,list buttons)
{
    clean();
    menu_channel = (integer)(llFrand(99999.0) * -1);
    menu_handler = llListen(menu_channel,"",user,"");
    llDialog(user,title,buttons,menu_channel);
    llSetTimerEvent(60.0);
}
clean()
{
    llSetTimerEvent(0.0);
    llListenRemove(menu_handler);
}

// Global variables
list visitor_list;
float range = 10; // in meters
float rate = 1.0; // in seconds
 
 
// Functions
integer isNameOnList( string name )
{
    integer len = llGetListLength( visitor_list );
    integer i;
    for( i = 0; i < len; i++ )
    {
        if( llList2String(visitor_list, i) == name )
        {
            return TRUE;
        }
    }
    return FALSE;
}
 
// States
default
{
     on_rez(integer start_param)
    {
        // reset on rez
        llResetScript();
    }
 
 
    changed( integer change )
    {
        if(change & CHANGED_OWNER )
        {
            // reset script on change of Owner
            llResetScript();
        }
    }

    state_entry()
    {
        llSay(0, "Visitor Detection / Intruder Alert system activated");
        llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
        llListen(0, "", llGetOwner(), "");
    }
     
          touch_start(integer total_number)
    {
         if ( llDetectedKey(0) == llGetOwner() && NOTIFYOWNER == TRUE )
        {
        menu(llDetectedKey(0),"\nPlease Choose an Option:\n \nNotify Owner: enabled",["Visitor List","Reset List","Notify OFF","ScanRange","About"]);
        }
         if ( llDetectedKey(0) == llGetOwner() && NOTIFYOWNER == FALSE )
        {
        menu(llDetectedKey(0),"\nPlease Choose an Option:\n \nOnotify Owner: disabled",["Visitor List","Reset List","Notify ON","ScanRange","About"]);
        }
        
         if ( llDetectedKey(0) != llGetOwner() )
        {        
        llSay(0, "visitor alert system / intruder detector system v1.0.");
    }
}
                     
    sensor( integer number_detected )
    {        integer i;
        for( i = 0; i < number_detected; i++ )
        {
            if( llDetectedKey( i ) != llGetOwner() )
            {
                string detected_name = llDetectedName( i );
                if( isNameOnList( detected_name ) == FALSE )
                {
                     if (llGetListLength(visitor_list) > MAXLISTSIZE) {
                     visitor_list = llDeleteSubList(visitor_list,0,0);
                    }

                    visitor_list += detected_name;
                    if (NOTIFYOWNER == TRUE)
                    {
                     llInstantMessage(llGetOwner(),"you have a visitor at " + llGetObjectDesc() + " thier name is " +detected_name);   
                    }
                }
            }
        }    
    }
    
        timer()
    {
        llSetTimerEvent(0.0);
        clean();
    }
    
    listen( integer channel, string name, key id, string message )
    {
        if( id != llGetOwner() )
        {
            return;
        }
        
            if (llSubStringIndex(message, "scanrange") == 0)
        {
            range = (float)llGetSubString(message, 10, -1);
            llOwnerSay("ScanRange set to '"+(string)range+"'");
            llSensorRemove();
            llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
        }
        else
        if( message == "ScanRange" )
        {
            llOwnerSay((string)ScannerItems);
            llOwnerSay("Please choose one of the suggested Scan Distances without the 'M'");
            llOwnerSay("for example type 'scanrange 20'");
        }
        else
        if( message == "Visitor List" )
        {
            llSay( 0, "Visitor List:" );
            integer len = llGetListLength( visitor_list );
            integer i;
            for( i = 0; i < len; i++ )
            {
                llSay( 0, llList2String(visitor_list, i) );
            }
            llSay( 0, "Total = " + (string)len );
        }
        else
        if( message == "Reset List" )
        {
            visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
            menu(id,"\nReset Complete",["Ok"]);
        }
        else
                if( message == "Notify ON" )
        {
            NOTIFYOWNER = TRUE;
            llSay( 0, "NOTIFICATION NOW SET TO ON");
        }
        else
            if( message == "Notify OFF" )
        {
            NOTIFYOWNER = FALSE;
            llSay( 0, "NOTIFICATION NOW SET TO OFF");
        }
        else
            if( message == "Promixity ON" )
        {
            NOTIFYOWNER = TRUE;
            llMessageLinked(LINK_ALL_CHILDREN, 2, "ON", NULL_KEY);
        }
        else
            if( message == "Promixity OFF" )
        {
            llMessageLinked(LINK_ALL_CHILDREN, 2, "OFF", NULL_KEY);
        }
    }        
}


Link to comment
Share on other sites

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