Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

List problem

DarkLiquid Dalgleish
Registered User
Join date: 15 May 2006
Posts: 2
04-03-2007 08:40
I have a problem with this script.. it WILL NOT load the list properly. It refuses to give out the notecard and it spams "Not in list". I'm lost.. help please :)

CODE

// Global variables
list visitor_list;
integer MAX_LIST_LENGTH = 50;

// Functions
integer isNameOnList(string name)
{
integer len = llGetListLength(visitor_list);
integer i;
llOwnerSay("Checking List Length");

for (i = 0; i < len; i++);
{
if(llList2String(visitor_list, i) == name )
{
llOwnerSay("On List");
return TRUE;
}
return FALSE;
}
}

// States
default
{
state_entry()
{
llSay(0, "Bump Giver Started");
llVolumeDetect(TRUE);
}


collision_start( integer num_detected )
{
string detected_name = llDetectedName(0);
integer len = llGetListLength(visitor_list);
integer i;

for (i = 0; i < len; i++);
{
if (llDetectedType(0) & AGENT)
{
llOwnerSay("Checking List");
if( isNameOnList(detected_name) == FALSE )
{
visitor_list = (visitor_list=[]) + visitor_list + detected_name;
llGiveInventory(llDetectedName(0),llGetInventoryName(INVENTORY_NOTECARD, 0));
llOwnerSay("Not on list");
}
}
}
}

collision_end(integer num_detected)
{
string detected_name = llDetectedName(0);
integer len = llGetListLength(visitor_list);

if( isNameOnList(detected_name) == FALSE )
{
llOwnerSay("Not on list");
llGiveInventory(llDetectedName(0),llGetInventoryName(INVENTORY_NOTECARD, 0));
}

if(len == MAX_LIST_LENGTH)
{
llOwnerSay("List full.. clearing");
visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
}

}
}


RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
04-03-2007 08:44
I think your return FALSE should be OUTSIDE your for loop.

(Also you could use llListFindList to seach the list instead).

Rj
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-03-2007 08:56
A few things jump out at me:-

Firstly llGiveInventory requires a key not a name
Secondly use llListFindList rather than iterate the list your self.
Thirdly you should be using num_detected not the list length to index the Detected functions. But you should also use the index and not just 0.


CODE

// Global variables
list visitor_list;
integer MAX_LIST_LENGTH = 50;

// States
default
{
state_entry()
{
llOwnerSay("Bump Giver Started");
llVolumeDetect(TRUE);
}


collision_start( integer num_detected )
{
integer i;

for (i = 0; i < num_detected; i++);
{
if (llDetectedType(i) & AGENT)
{
string detected_name = llDetectedName(i);
llOwnerSay("Checking List");
integer index = llListFindList( visitor_list, [ detected_name ]);
if( index < 0)
{
llOwnerSay(detected_name + " is not on the list. Adding");
visitor_list = (visitor_list=[]) + visitor_list + detected_name;
llGiveInventory(llDetectedKey(i),llGetInventoryName(INVENTORY_NOTECARD, 0));

integer len = llGetListLength(visitor_list);
if(len >= MAX_LIST_LENGTH)
{
llOwnerSay("List full.. deleting oldest");
visitor_list = llDeleteSubList(visitor_list, 0, 0);
}
}
}
}
}

}

I've changed your code slightly, now instead of clearing the entire list it just deletes the oldest entry.