Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Taking something away from a list

Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-19-2005 18:54
I am making a list that needs to be able to take away names that it has already added. I have a list players, then when I add a name to it, I add the string playr, like so: players += [playr]; . Now when I want to take a specific name from the list, I tried players -= [message], from a listen() event. This doesn't work though. Any suggestions?
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
03-19-2005 19:09
Hi,

I haven't actually compiled this, but it should be close.

If your list is called my_list and the entry to be deleted is bad_entry, then

CODE

integer bad_entry_position = llListFindList( my_list, [ bad_entry ] );

if ( -1 < bad_entry_position ) {
llListDeleteSubList( my_list, bad_entry_position, bad_entry_position );
}


-- judah
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-19-2005 19:52
Hi, doesn't seem to be working correctly yet. Here's what I have:

integer takeaway = llListFindList( players, [ message ] );
if ( -1 < takeaway )
{
llDeleteSubList( players, takeaway, takeaway );
}

where takeaway is bad_entry_position, players is the list, and message is the bad_entry. The message is from a listen() event, so I don't know if this is the problem or not.
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
03-19-2005 20:09
Read the wiki here

The important part for you is:
From: someone
IMPORTANT NOTE: This function does not manipulate src directly. To manipulate the list you pass as src, you must set src equal to the return value of this function.


so for your code, the delete line should be:
CODE
players= llDeleteSubList( players, takeaway, takeaway );
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
03-19-2005 20:13
Oops, sorry about that, Douglas, and thanks for the catch, Spuds.

Should've double-checked before I posted.

-- judah
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-19-2005 20:33
hey, thanks! its working now. One more question relating to lists (they are not my specialty :p ). I have players enter this list by touching an object, but I want them to only be able to enter once. How would I do this? Here's what I tried:

integer play = llListFindList(players, [ playr ] );
if ( -1 < play )
{
players += [playr];
llSay(849330, "" + (string) playr + "";);
llSay(0, "" + (string) players + "";);
}
else
{
llInstantMessage(player, "You have already entered this round";);
}
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
03-19-2005 20:50
The only thing that looks wrong to me is your if-test.

The way you have it set up, I think the only way they can get on the list is if they're already on it.

You probably want

CODE

if (-1 == play )


Oh, and are those empty strings you're using to bracket your llSay messages? I'm a little bleary-eyed, (step AWAY from the game, Judah) so I can't quite tell. But if they are, I think you can drop them.

And if you cast your entire list to a string at once for chatting, you won't get any breaks between the entries...the string will come out something like
CODE

"Judah JimadorSpuds MilkDouglas Callahan"

which may not be what you want. The wiki page on llList2CSV may give you something a little more useful.

-- judah
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-19-2005 20:58
Thanks again, its working. I have one more request :p . I want to make a list with names and scores that go with those names. I want to be able to add to the score of certain people on the list, and be able to get the highest scorer. Is there anyway to do this?
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
03-19-2005 21:06
Do you need to be able to list the names sorted by score, or just pick the high score out of the list and find the matching name?

-- judah
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-19-2005 21:10
well, a list of the top scores would be better, like the top 10 scores or something of the sort. But I would have to be able to pick these scores out of the list
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
03-19-2005 21:47
CODE

//
// Strided list...alternating current scores and names. Scores come first.
//
list scores = [];

//
// This add function increments an avie's score; doesn't reset it from scratch.
// Also does lazy initialization on the avie name.
//

add_to_score( string avie_name, integer new_points )
{
integer pos = llListFindList( scores, [ avie_name ] );
integer current_score;
if ( -1 == pos ) {
current_score = 0;
} else {
current_score = llList2Integer( scores, pos - 1 );
}
current_score += new_points;

if ( -1 < pos ) {
scores = llDeleteSubList( scores, pos - 1, pos );
}

scores += [ current_score, avie_name ];
}

//
// This reporting function will give you back a high-to-low list of scores, like
// [ 15, "Mae Best", 12, "Judah Jimador", (etc.)]
//

list sorted_scores()
{
return llListSort( scores, 2, FALSE ); // high to low
}



I don't know how comfortable you are with scripting in general...if this doesn't make sense, send up a flare :)

-- judah
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-20-2005 00:08
This is great man, thanks alot for all the help! :D
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-20-2005 13:12
One more thing from that script. How would I get the top scorer's name only, without the number, or the top number without the name. And if I wanted to have a touch_start() event that would let a person touch it, then find their score, how would I incorporate this?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
03-20-2005 13:28
I'm too shattered to do the coding, but:

CODE

llList2String(listname, 1) //will be the name of the top scorer.

touch_start(integer times)
{
integer find=llListFindList(listname, [llDetectedKey(0)]);
llInstantMessage(llDetectedKey(0), "Your score is "+llList2String(listname, find - 1)+" you came "+(string)(find/2));
} //or something like this, should IM someone who touches it their score and position.
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-20-2005 14:33
llList2String(listname, 1) //will be the name of the top scorer.

This does not work because the list consists of [ current_score, avie_name ]. I need the avie_name that corresponds with the highscore. How can I get this out of the list.
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
03-20-2005 15:07
Hi Douglas!

If you use the way I outlined, your sorted list will have the high-scoring name in the second slot (Position #1, since the slots are numbered from zero).

So, in simplest form, I think the function

CODE


string high_scorer()
{
//
// Tiny bit of example bullet-proofing...don't know how you're
// setting the system up, so I don't know if this could ever get called
// when there are no enrolled players...
//
if ( 2 > llGetListLength( scores ) )
return "**NO PLAYERS**";
else
return llList2String( sorted_scores, 1 );
}



would get you _a_ highest-scoring avie name, but not necessarily the only one. Which reminds me...what to do about ties?

-- judah
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
03-20-2005 15:13
ok ties. Well it doesn't really matter as long as the script doesn't get confused or something. Won't the list go by alphabetical order or the name if the score is the same? And do you know anything about Xy text, I'm trying to put this scoreboard up. You wanna meet ingame Judah?
Judah Jimador
Registered User
Join date: 13 Mar 2005
Posts: 230
03-20-2005 16:52
I don't know the details, but I expect the built in list sort is a "stable" one WRT the other parts of each stride. That means that, in the case of ties, you'd get back the avie names beginning with the least recently updated score. If that's an issue, let me know; there's another technique you can use which will sort names (by first and then last) within a tying score. May be a tiny bit slower on updating scores, though.

I've glanced at some of the docs for XYText, but haven't tried it yet.

I'm really only getting used to LSL myself, so please don't mistake me for a fully-competent scripter :-p

-- judah
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
03-21-2005 01:54
I think I'm saying the same thing as Judah, but I can tell you for sure that if two things on llListSort() have the same value then it puts the one with the lower index in first. It does NOT move on to assess other parts of the stride if you are sorting with strides.