Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Find key in list of keys

FoxyHollow Guardian
Registered User
Join date: 29 Oct 2009
Posts: 9
12-02-2009 16:22
I am trying to create an staff tipjar that does not depend on profile pictures, but instead pictures from the inventory.

The script is reading an notecard where I save the keys from the staff that should have login rights to the tipjar.
At the moment, it does only contain 2 keys. Mine and an alt.
b6702d66-030a-4707-a54c-2a7f0799150d
29d181f7-555c-4b03-95fb-94716755bf42

The script (which isn't finnished yet mind you), looks like this:

CODE

integer perm;
list managers = ["29d181f7-555c-4b03-95fb-94716755bf42", "b6702d66-030a-4707-a54c-2a7f0799150d"];
string gName = "HOSTS"; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries
string gStrTxt;
list hosts = [];
integer LOGGEDIN;
string hostname;

default
{
state_entry()
{
llSetColor(<0.0,0.0,0.0>, ALL_SIDES);
llSetColor(<1.0,1.0,1.0>, 0);
llScaleTexture(1.0, 1.0, 0);
llSetTexture(TEXTURE_BLANK, ALL_SIDES);
llSetTexture("FoxySign",0);
llSetText("Foxy staff tipjar", <1.0,0.0,0.0>,1.0);
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
state check_perm;
}
}

state check_perm
{
run_time_permissions(integer mask)
{
perm = llGetPermissions();
if ( PERMISSION_DEBIT & perm )
{
llWhisper(0, "Permissions granted, ready...");
state tips;
}
else
{
integer listlength = llGetListLength(managers);
integer i;
while((i < listlength))
{
llDialog(llList2Key(managers,i), "The foxy host tipjar needs to be granted debit permissions again!", ["OK"], -1864809);
i ++;
}
state inactive;
}
}
}

state inactive
{
state_entry()
{
llSetTimerEvent(900.0);
}
timer()
{
state default;
}
}

state tips
{
state_entry()
{
gQueryID = llGetNotecardLine(gName, gLine);
}

dataserver(key query_id, string data)
{
if (query_id == gQueryID)
{
if(data != EOF)
{
hosts += [data];
++gLine;
gQueryID = llGetNotecardLine(gName, gLine);
}
}
}

touch_start(integer touched)
{
key toucher = llDetectedKey(0);
integer position = llListFindList(hosts,(list)toucher);
key hostkey = llList2Key(hosts,position);
llOwnerSay("hostlist: " +llDumpList2String(hosts," - ") +"\ntoucher: " +(string)llDetectedKey(0));
if (LOGGEDIN == FALSE && toucher == hostkey)
{
hostname = llKey2Name(hostkey);
llSetText(hostname +"´s tipjar", <1.0, 0.0, 0.0>, 1.0);
llSetTexture(hostname, 0);
llScaleTexture(1.0, 1.0, 0);
LOGGEDIN = TRUE;
}
else if (LOGGEDIN == TRUE && toucher == hostkey)
{
llWhisper(0, "Sorry, " +hostname +" is currently logged in. If this is your shift, ask current host to log out or contact the venue manager/owner");
}
else if (toucher != hostkey)
{
llWhisper(0, "Sorry, your key doesn't mach with any of our hosts keys");
}
}
}


For some reason when I am using llListFindList to search for the key in the list "hosts", it always end up giving me -1 as result.

Is there any reasons to why I can not search for an key in the list like I am doing? Or have I forgot something?
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
12-02-2009 16:27
In the dataserver you are saving the UUIDs as strings, but down in this line you are looking for a key:

integer position = llListFindList(hosts,(list)toucher);

A quick change would be to:

integer position = llListFindList(hosts, [(string)toucher]);


Keys and strings have an odd relationship, some functions treat them interchangeably while others (like llListFindList) treat them as separate types.
FoxyHollow Guardian
Registered User
Join date: 29 Oct 2009
Posts: 9
12-02-2009 16:55
yet another proof that you never stop to learn new things. Thanks. :p