Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

List Redundancy Prevention

Doc Nerd
Registered User
Join date: 7 Oct 2005
Posts: 20
11-16-2005 12:58
Okay, back on my little project at hand, I want it to sort of log who's touched it. Simple enough with

List += [llKey2Name(llDetectedKey(0))];

BUT!....even with the touch spam prevention, the list still logs the same person into the list. So if I touch it, wait the 10 second interval, then touch it again, the list will return with my name twice.

Is there a way I can prevent the same name from being spewed out multiple times, or even better yet, have the list change multiple same values as a multiple? (i.e. "Doc Nerd x n" where n is the number of times I've touched it more than once.)
Jokey Domela
Registered User
Join date: 27 Jul 2005
Posts: 83
11-16-2005 13:19
Well, on touch you could loop over the elements of your list and compare it to the detected toucher. If theres a match, do nothing, otherwise add them.

For your second idea, you could just double up on your list. Name,times,name,times,name,times so on and so forth. Loop over the list, if theres a match, increment the next element by 1. If it's a new person, just add 2 elements to the end of your list...name,1.
Lit Noir
Arrant Knave
Join date: 3 Jan 2004
Posts: 260
11-16-2005 13:25
Seems like llListFindList before the add would do. If already there, either don't add, delete the old one (easy now that you already have the list index) then add (if you want to keep the latest), or have the list strided and increment a "count" number.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
11-16-2005 13:31
If you only need a list of unique names, and don't care about keeping track of how many times a certain person has touched the object, that's pretty easy to do. LSL has a function to search a list for an entry, so just use that to first check the list to see if the name is already in there. If it is, do nothing, else add the name.

CODE

touch_start(integer num)
{
string name = llDetectedName(0);

if (llListFindList(NamesList, [name]) == -1)
{
NamesList += [name];
}

// Else do nothing
}


If you need to keep track of the number of touches, then it gets a little more complex - find the entry, get the next entry (which will be an integer), increment it, then replace it back so the number against that name has the updated count. Basically what Jokey said, except you don't need to loop over the list checking each item, you can use the built-in LSL function to search the list. And you can use llDetectedName(0) instead of llKey2Name(llDetectedKey(0)). They'll both work, one takes a few less characters to type and may run unnoticably faster :)

Edit: OK, someone beat me to it again. What Lit said :)
Doc Nerd
Registered User
Join date: 7 Oct 2005
Posts: 20
11-16-2005 13:32
Lit, I think you got the idea I was looking for. I've been looking at the strided list function for this purpose, but couldn't find a way to use it the way I wanted. Thanks for the help. I'll try using that once I get back in-world.

Ziggy, doesn't the llDetectedKey return the actual key (abcdef-1410-1243h-asf70-yadda-yadda) rather than the actual name of the object/agent? Or have I not read the wiki right?
Doc Nerd
Registered User
Join date: 7 Oct 2005
Posts: 20
11-16-2005 18:31
Okay, same topic, different crazy way to implament it; is there a way I can create a list who's name is a temporary variable?
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-16-2005 20:47
CODE

list example;
string name;

default
{
touch_start(integer whatever)
{
name = DetectedName(0);
llSay(0, "hi " + name);
example += name;
}
}


you mean something like that ?
Kala Bijoux
Material Squirrel
Join date: 16 Nov 2004
Posts: 112
11-16-2005 23:34
From: Doc Nerd
Ziggy, doesn't the llDetectedKey return the actual key (abcdef-1410-1243h-asf70-yadda-yadda) rather than the actual name of the object/agent? Or have I not read the wiki right?


llDetectedKey returns the key, llDetectedName returns the name. So llKey2Name(llDetectedKey(0)) is the same thing as llDetectedName(0).
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
11-17-2005 02:11
Of course...if you're going to store an avatar in a list, it's perfectly easy to store the key...and as there is no llName2Key command, saving the key is--slightly--more versatile on callback.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
11-17-2005 06:59
From: Kenn Nilsson
Of course...if you're going to store an avatar in a list, it's perfectly easy to store the key...and as there is no llName2Key command, saving the key is--slightly--more versatile on callback.
Personally, I'd save both if I wanted to be able to get the name, because llKey2Name doesn't work if the object is off-sim or not rezzed in-world.
Alondria LeFay
Registered User
Join date: 2 May 2003
Posts: 725
11-17-2005 07:04
From: Argent Stonecutter
Personally, I'd save both if I wanted to be able to get the name, because llKey2Name doesn't work if the object is off-sim or not rezzed in-world.


Only AV's would be touching. Thus, you can use llRequestAgentData(<key>,DATA_NAME).

Have something in the code though to prevent the list from growing past the available data or it will inevitably crash.