Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Why ain't this working??????

Random Torok
Registered User
Join date: 19 Mar 2007
Posts: 33
10-03-2007 22:38
The code below is suppose to take a list named test then look to see if llDetectedName is in the list. It works if llDetectedName is the first item in the list.

CheckAccess(list test)
{
AccessGranted = 0;
integer i = 0;
integer end = llGetListLength(test);
string AvDetected =llDetectedName(0);
for (; i<end; ++i)
{
string ListItem = llList2String(test, i);
if (AvDetected == ListItem)
{
AccessGranted = 1;
}
}
}

All comments appreciated.
RT
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
10-03-2007 23:09
You may want to use llListFindList.

http://wiki.secondlife.com/wiki/LlListFindList
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
10-03-2007 23:32
Not much info to go on here without seeing the code calling it. You might try it this way instead:

CODE


integer CheckAccess(list test)
{
return llListFindList(test, [llDetectedName(0) ]) >= 0;
}



I assume this is being called from a touch event, since you are assuming that only the first detected name is significant. You might want to step from 0 through llDetectedName(num_detected - 1) to check all the detected names.

Be aware that llDetectedName() will only work within events that set it (sensor, touch, collision, etc). Otherwise it's meaningless.

Your function looks okay, have you printed out your list from memory to be sure that the other entries are present and not corrupted in some way?
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
10-04-2007 00:25
to my recolection... you can't even use llDetected.. methods in your own functions even if they are called from e.g. a touch event... !?

however, since it's only a one-liner function, you can do without the function entirely and just use llListFindList
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
10-04-2007 01:34
Lies, all lies! Who has been filling your head with such lies?!

Yes, you can invoke llDetected... from within functions, as long as you only call them from events where they are significant.

CODE


list_touchers(integer count)
{
while (count--)
llOwnerSay(llDetectedName(count));
}

default
{
touch_start(integer total_number)
{
list_touchers(total_number);
}
}

Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
10-04-2007 02:40
From: Boss Spectre
Lies, all lies! Who has been filling your head with such lies?!

Yes, you can invoke llDetected... from within functions, as long as you only call them from events where they are significant.

CODE


list_touchers(integer count)
{
while (count--)
llOwnerSay(llDetectedName(count));
}

default
{
touch_start(integer total_number)
{
list_touchers(total_number);
}
}



It's true that you can use llDetected* in functions called from sensor, touch etc events. However, doing so restricts where you can use the function in the future.

I'd recommend passing the name of the av in as a parameter, even though it's not strictly necessary in this case - you never know when you might need to do this again, but with an avatar name from a different source.
_____________________
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
10-04-2007 03:33
From: Random Torok

string AvDetected =llDetectedName(0);
for (; i<end; ++i)
{


for (i; i<end; ++i), missing the first i in that statement.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Flennan Roffo
Scripter
Join date: 29 Sep 2007
Posts: 26
10-04-2007 05:14
From: nand Nerd
for (i; i<end; ++i), missing the first i in that statement.


Make that: for (i=0; i < end;++i) else the first expression would be quite useless.
_____________________
Logic Scripted Products and Script Services
Peacock Park (187,228,69)

*** Get your free copy of SL Mail today! ***
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
10-04-2007 05:18
From: Flennan Roffo
Make that: for (i=0; i < end;++i) else the first expression would be quite useless.

doh :o
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-04-2007 07:31
From: Flennan Roffo
Make that: for (i=0; i < end;++i) else the first expression would be quite useless.

Can somebody test that? I think "integer i = 0; for ( ; i < 10; ++i)" is the same as "integer i; for (i = 0; i < 10; ++i)".

/me votes that this function is not being called from from an event that likes llDetected..
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Random Torok
Registered User
Join date: 19 Mar 2007
Posts: 33
Tried but still not working
10-04-2007 07:38
ok I've tried some of the suggestions made but still doesn't work so I'll post the whole script.

Ultimately what I am trying to accomplish with this is when someone touches the object if thier name is found in the list on the Configuration card then the script will run.

The Configuration card for this bit of code simply has a line in the following form.
AV1, Random Torok, AV2.

The list does seem to be valid because if I step through the elements of this list and display them they come up fine.

This script works if llDetectedName is the first element on the list.

//begin code
key ListKey;
string cName = "Configuration";
list Access;
integer AccessGranted;

CheckAccess(list test)
{
AccessGranted = 0;
integer i = 0;
integer end = llGetListLength(test);
string AvDetected =llDetectedName(0);
for (; i<end; ++i)
{
string ListItem = llList2String(test, i);
if (AvDetected == ListItem)
{
AccessGranted = 1;
}
}
}

default
{
state_entry()
{
ListKey = llGetNotecardLine(cName, 0);
}

dataserver(key query_id, string data)
{

if(query_id == ListKey)//Filtering the call
{
if (data != EOF) // not at the end of the notecard
{
Access = llParseString2List(data, [","],[]); //Give Access the same value as data.
//Data being what is read from the notecard
}
}
}
touch_start(integer total_number)
{
CheckAccess(Access);
if(AccessGranted == 1)
{
llSay(0, "You have access";);
}
else
{
llSay(0, "You do not have access";);
}
llResetScript();
}
}

//end code
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
10-04-2007 07:59
From: Random Torok
ok I've tried some of the suggestions made but still doesn't work so I'll post the whole script.

Ultimately what I am trying to accomplish with this is when someone touches the object if thier name is found in the list on the Configuration card then the script will run.

The Configuration card for this bit of code simply has a line in the following form.
AV1, Random Torok, AV2.

The list does seem to be valid because if I step through the elements of this list and display them they come up fine.

This script works if llDetectedName is the first element on the list.

//begin code
key ListKey;
string cName = "Configuration";
list Access;
integer AccessGranted;

CheckAccess(list test)
{
AccessGranted = 0;
integer i = 0;
integer end = llGetListLength(test);
string AvDetected =llDetectedName(0);
for (; i<end; ++i)
{
string ListItem = llList2String(test, i);
if (AvDetected == ListItem)
{
AccessGranted = 1;
}
}
}

default
{
state_entry()
{
ListKey = llGetNotecardLine(cName, 0);
}

dataserver(key query_id, string data)
{

if(query_id == ListKey)//Filtering the call
{
if (data != EOF) // not at the end of the notecard
{
Access = llParseString2List(data, [","],[]); //Give Access the same value as data.
//Data being what is read from the notecard
}
}
}
touch_start(integer total_number)
{
CheckAccess(Access);
if(AccessGranted == 1)
{
llSay(0, "You have access";);
}
else
{
llSay(0, "You do not have access";);
}
llResetScript();
}
}

//end code


I haven't tested it because I'm at work. But does your notecard have spaces after the commas? If it does, all av names except the first one will have a space in front of it, causing the comparison in CheckAccess to fail. And when you display them, they will probably look ok.
_____________________
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-04-2007 08:05
From: Stephen Zenith
I haven't tested it because I'm at work. But does your notecard have spaces after the commas? If it does, all av names except the first one will have a space in front of it, causing the comparison in CheckAccess to fail. And when you display them, they will probably look ok.

I was just about to guess that the notecard reading is funky, too..
Try this...
CODE

CheckAccess(list test)
{
AccessGranted = 0;
integer i = 0;
integer end = llGetListLength(test);
string AvDetected =llDetectedName(0);

for (; i<end; ++i)
{
string ListItem = llList2String(test, i);
llOwnerSay ("checking name '" + ListItem + "'");
if (AvDetected == ListItem)
{
AccessGranted = 1;
}
}
}
[/
CODE

...and look closely at the output.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
10-04-2007 08:09
Or you could try hardcoding the list to check it, rather than reading it from a notecard.

So disable the notecard reading section, and replace

list Access;

with

list Access = ["AV1", "Random Torok", "AV2"];

at the top.
_____________________
Random Torok
Registered User
Join date: 19 Mar 2007
Posts: 33
whooo hoooo
10-04-2007 08:18
Thankyou everyone for your assistance. Stephen's suggestion did the trick. I took out the spaces after the commas and my code works great. Now to clean it up.

I had tried using a for loop to display the list but never noticed the extra space in there.

Just as a curiosity how would I get the llParseString2List function to cast off that space?

Thanks again to all.
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
10-04-2007 08:26
From: Random Torok
Thankyou everyone for your assistance. Stephen's suggestion did the trick. I took out the spaces after the commas and my code works great. Now to clean it up.

I had tried using a for loop to display the list but never noticed the extra space in there.

Just as a curiosity how would I get the llParseString2List function to cast off that space?

Thanks again to all.


llStringTrim - trims whitespace at the beginning, end or both of string. It only works on strings, not on lists of strings, so you'll either need to loop around the list of avs after you've read it from the notecard, or strip it when you do the comparison.

If you do the second way, it'll stop you replacing your loop with llFindListFind, which is something you probably want to do. So I'd add a function that takes the populated list of avs and cleans up any whitespace on each entry. Then call it after you've read your line from the notecard.
_____________________
Mereille Despres
Registered User
Join date: 5 Sep 2007
Posts: 79
10-04-2007 08:28
::: What Stephen Said :::
Trevor Langdon
Second Life Resident
Join date: 20 Oct 2004
Posts: 149
10-04-2007 16:41
Random--

You could use the new llStringTrim function to strip of any leading or trailing spaces.

Here's an exampe:

llStringTrim(" Testing 1 2 3 ", STRING_TRIM);

Would produce:
"Testing 1 2 3"


p.s. Stephen beat me to it. I agree with Stephen, best to cleanup the AV list of names as you read/build your list. So have a temp list variable that can be used to parse the notecard record to a list, then append to the Access list variable using something like:

CODE

// where 'test' is the parsed-string-to-list from your notecard read

integer i;
integer end = llGetListLength(test);

for (i=0; i<end; ++i)
{
// Memory efficient way for appending new elements to a list
Access = (Access=[]) + Access + [llStringTrim(llList2String(test, i), STRING_TRIM)];
}
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-05-2007 08:55
I think some of this would get easier if the notecard was changed to be one-line-per-name..

That and since you hit up the asset server on reset, it'd be more friendly to not reset the script unless you get a changed/INVENTORY event. Unless you have some other reason to reset it, of course.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left